Quantcast
Channel: Cadence Technology Forums
Viewing all articles
Browse latest Browse all 63090

Forum Post: RE: Scheme version of apply

$
0
0
Hi Aurélien, It's not really clear what your end goal is (I'm assuming this is just a cut-down example to illustrate the problem), but fundamentally the issue is not with apply here - it's the fact that the function object created by the lambda (on the fly, at run time) is being created outside of the lexical environment. There's a small typo in your code - it should have been ( (apply lambda (make_args) '(plus a b) nil) 27) because otherwise it would have been trying to do the addition before the function is created, and clearly a would have not been in scope then. However, even with that correction, it still doesn't work because the variable b is not in scope when the resulting function object is called, because it's been created in the lexical environment. Since you are actually creating a new function object at run time, there's really no disadvantage to using eval here - in either case it's going to have to do the function creation and compilation. So this will work: x=(let ((b 12)) (defun make_args nil '(@optional a)) ((eval `(lambda ,(make_args) (plus a b)) (theEnvironment)) 27) );let Having chatted about this with my team, we suspect that there might be a more elegant solution to your problem if we knew what you're really trying to do rather than this rather abstract example. That said, if you are creating code at run time, there isn't really an alternative to using eval - and that's precisely what it's useful for. Regards, Andrew.

Viewing all articles
Browse latest Browse all 63090

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>