<div class="gmail_quote">On Thu, Oct 13, 2011 at 10:25 AM, Canhua <span dir="ltr"><<a href="mailto:dreameration@gmail.com">dreameration@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Thank you for your suggestion. I should work. And I may also use a<br>
variable name for "x" that isn't possible to conflict (use gensym).<br>
So, yes, there are ways to work around this issue. But I learnt that<br>
"let over lambda" in parenscript is different from that in common<br>
lisp. Is that right?<br></blockquote><div><br></div><div>Yes, because Parenscript's target is JavaScript the semantics of many operations is different from Common Lisp's.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
The reason why I want need this is that I have to pass the whole<br>
object as argument to a library function. Many js libraries seem like<br>
to use object as configuration argument.<br></blockquote><div><br></div><div>In this case you probably don't need a closure as object's "member" function.</div><div><br></div><div>vsevolod</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5"><br>
On Thu, Oct 13, 2011 at 3:13 PM, Vsevolod Dyomkin <<a href="mailto:vseloved@gmail.com">vseloved@gmail.com</a>> wrote:<br>
> I suggest, that you first consider, how would you do that in JS. You'll need<br>
> to wrap that in functions:<br>
> {<br>
> 'fn_1' : (function () {<br>
> var x = 1;<br>
> return function () { return x; } }) (),<br>
> 'fn_2' : (function () {<br>
> var x = 2;<br>
> return function () { return x; } }) ()<br>
> }<br>
> Now let's think, how this can be done in Parenscript?..<br>
> PS. But the most important question is: why do you need to create a single<br>
> function, that closes over a "private" variable, as part of an object? Isn't<br>
> it equivalent to just coding the value of the variable inside the function?<br>
> vsevolod<br>
><br>
><br>
> On Thu, Oct 13, 2011 at 10:05 AM, Canhua <<a href="mailto:dreameration@gmail.com">dreameration@gmail.com</a>> wrote:<br>
>><br>
>> actually what I want to achieve is something like this:<br>
>> (create "fn_1" (let ((x))<br>
>> #'(lambda ()<br>
>> x))<br>
>> "fn_2" (let ((x))<br>
>> #'(lambda ()<br>
>> x)))<br>
>> and I expected these two "x" are lexical-scope separate and so<br>
>> independent from each other.<br>
>> However the compiled js code doesn't work as I expected.<br>
>><br>
>><br>
>> On Thu, Oct 13, 2011 at 2:51 PM, Vsevolod Dyomkin <<a href="mailto:vseloved@gmail.com">vseloved@gmail.com</a>><br>
>> wrote:<br>
>> > Hi<br>
>> > Actually the above code is correct.<br>
>> > You can also use:<br>
>> > - either<br>
>> > (let (x)<br>
>> > (create "fn" (lambda () x)))<br>
>> > - or<br>
>> > (create "x" nil<br>
>> > "fn" (lambda () x)))<br>
>> > depending on the JS semantics you want to get.<br>
>> > vsevolod<br>
>> ><br>
>> ><br>
>> > On Thu, Oct 13, 2011 at 8:40 AM, Canhua <<a href="mailto:dreameration@gmail.com">dreameration@gmail.com</a>> wrote:<br>
>> >><br>
>> >> hi, all, I found that<br>
>> >> (create "fn" (let ((x))<br>
>> >> (lambda () x)))<br>
>> >><br>
>> >> compiles to<br>
>> >> { 'fn' : (x = null, function () {<br>
>> >> return x;<br>
>> >> }) }<br>
>> >><br>
>> >> wherein the variable x may conflict with a variable with the same name<br>
>> >> outside this code.<br>
>> >> How may avoid this? How may I achieve "let over lambda" closure effect<br>
>> >> as in common lisp?<br>
>> >><br>
>> >> Thanks.<br>
>> >><br>
>> >> _______________________________________________<br>
>> >> parenscript-devel mailing list<br>
>> >> <a href="mailto:parenscript-devel@common-lisp.net">parenscript-devel@common-lisp.net</a><br>
>> >> <a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > parenscript-devel mailing list<br>
>> > <a href="mailto:parenscript-devel@common-lisp.net">parenscript-devel@common-lisp.net</a><br>
>> > <a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
>> ><br>
>> ><br>
>><br>
>> _______________________________________________<br>
>> parenscript-devel mailing list<br>
>> <a href="mailto:parenscript-devel@common-lisp.net">parenscript-devel@common-lisp.net</a><br>
>> <a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
><br>
><br>
> _______________________________________________<br>
> parenscript-devel mailing list<br>
> <a href="mailto:parenscript-devel@common-lisp.net">parenscript-devel@common-lisp.net</a><br>
> <a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
><br>
><br>
<br>
_______________________________________________<br>
parenscript-devel mailing list<br>
<a href="mailto:parenscript-devel@common-lisp.net">parenscript-devel@common-lisp.net</a><br>
<a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
</div></div></blockquote></div><br>