|
From: John B. <mr...@gm...> - 2015-07-14 02:20:05
|
These mean the same thing:
: add-quot ( n -- quot ) '[ _ + ] ;
: add-quot ( n -- quot ) [ + ] curry ;
:: add-quot ( n -- quot ) [ n + ] ;
They are basically different ways of currying the 'n' argument into the
quotation that is produced by ``add-quot``.
Best,
John.
On Sun, Jul 12, 2015 at 6:41 PM, Hugh Aguilar <hug...@ya...>
wrote:
> Does that work if the quotation accesses the local variables?
>
> Where are the local variables? Are they on the return-stack or in a heap
> block?
>
> Why do you say '[ _ + ] rather than just [ + ] ?
>
> thanks for your help --- Hugh
>
>
>
>
> Do you mean something like this?
>
> : add-quot ( n -- quot ) '[ _ + ] ;
>
> { 1 2 3 } 10 add-quot map .
>
> Yields:
>
> { 11 12 13 }
>
> Note: this works in the listener with the non-optimizing compiler, but if
> you tried to use this in compiled you'd need to add a static call effect to
> the quot by either making ``add-quot`` inline, or currying it with ``[
> call( x -- x ) ]``.
>
>
>
>
> On Fri, Jul 10, 2015 at 8:09 PM, Hugh Aguilar <hug...@ya...>
> wrote:
>
> > Jul 9 at 8:19 PM
> > I sent this yesterday but it seems to have gotten lost --- if it ends up
> > being double-posted, I apologize.
> >
> > Can quotations in Factor still be executed after the parent function has
> > gone out of scope (done its EXIT)? Scheme/Lisp allows this, and they hold
> > the local frame of the parent function on the heap rather than on the
> stack
> > so that it persists after the parent function has exited so the quotation
> > can still use it. It has to eventually get GC'd. LOTD definitely doesn't
> > have GC, because the FMITE is a micro-controller (also because we don't
> > have tagged data so there is no way to tell the difference between an
> > integer and a pointer except to know this a-priori).
> >
> > In LOTD I don't allow quotations to be executed after the parent function
> > has gone out of scope; the parent function's local-frame is on the stack
> so
> > it is lost when the parent function exits.
> >
> > In LOTD, a quotation could execute after the parent function has gone out
> > of scope if it doesn't access the parent function's local variables ---
> but
> > I disallow this too for consistency. The users should just use :NONAME
> for
> > anonymous functions that persist indefinitely --- quotations are for
> > situations where the anonymous function needs to communicate with the
> > parent, and it does so either through local variables or (if a
> bar-feature
> > higher-order function was used to call the quotation) on the data-stack.
> >
> > regards --- Hugh
>
>
>
> ------------------------------------------------------------------------------
> Don't Limit Your Business. Reach for the Cloud.
> GigeNET's Cloud Solutions provide you with the tools and support that
> you need to offload your IT needs and focus on growing your business.
> Configured For All Businesses. Start Your Cloud Today.
> https://www.gigenetcloud.com/
> _______________________________________________
> Factor-talk mailing list
> Fac...@li...
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
|