POV-Ray : Newsgroups : povray.off-topic : Standard libraries : Re: Standard libraries Server Time
9 Oct 2024 17:42:57 EDT (-0400)
  Re: Standard libraries  
From: Darren New
Date: 8 Mar 2009 00:09:20
Message: <49b35300$1@news.povray.org>
Warp wrote:
>   You still know that I get trolled when someone writes such mocking words
> about C++ as you have done.

You know, I took a couple hours away, then went back and looked at what I'd 
typed. I think if you look at my initial posts here objectively, you'll see 
they weren't mocking, as almost all of it was asking questions about the 
implementation.

What I failed to do was describe the mental process that caused me to ask 
the kinds of apparently-silly questions I was asking. I thought

(( Wow, C++ is getting lambdas. I guess they're standardizing Boost, which 
is ugly. )) "I bet it'll be ugly."

(( No, it actually *looks* not too bad. But I wonder how they implement it, 
then. That's a mess behind the scenes in C#, and in pretty much every 
language I know that keeps variables on the machine stack, so I wonder how 
they're doing closures. I wonder how the closed-over variables survive the 
destruction of the stack frame. ))

"Can you return lambda values from a function?"  (( Because if not, then you 
don't have to worry about the stack frame not being there. Oh, but I'm told 
you can. Cool. Maybe it's going to copy the values from the stack into a 
heap-allocated object. But how would it GC the heap-allocated object, if 
multiple lambdas point to it? Maybe it's doing reference counting. But that 
doesn't work, if you get circular references, which you can't get if you 
can't assign to a variable except a new variable. ))

"Can you assign it to a variable?"  (( Oh, you can do that too. Wow, that's 
really impressive. I can't imagine what they're doing to make closures work.))

"Thanks for the link to wikipedia."  (( Oh, wikipedia says you just randomly 
get hosed if you try to actually use values you thought you closed over when 
you created the lambda, unlike every other language that ever implemented 
the feature called 'lambda expressions'. ))

"Gee, C++ lambdas sure suck compared to everyone else's that actually 
manages to create a closure from lambdas."  (( I wonder what it could be 
useful for, since I can't think of a reason I'd use a lambda that I couldn't 
return from the function in which I created it. ))

"Why not just use a for loop?"  (( Oh, I see. I wasn't thinking like that, 
because I was still thinking in terms of lambdas rather than in terms of 
downward funargs. ))

I can see how if I didn't make clear why I was asking the questions, you 
might leap to the conclusion (perhaps justifiably) that I was simply looking 
for the flaws in order to criticize C++.  In reality, I was looking for the 
flaw in my mental model of how C++ handles memory that would allow the 
memory for the closure to be collected only after the lambda has been 
collected. Or, given that I'm pretty sure I understand how C++ works its 
memory model, I was looking for the cool impressive clever mechanism that 
would let the closure get allocated in a way that would work.

-- 
   Darren New, San Diego CA, USA (PST)
   My fortune cookie said, "You will soon be
   unable to read this, even at arm's length."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.