Re: binding free symbols in a lambda definition

2017-02-10 Thread Alexander Burger
Hi Lindsay, > # append > : (bench (let (N ()) (for X 1 (setq N (append N '(NIL (length N))) > 0.548 sec > -> 1 > > # cons > : (bench (let (N '()) (for X 1 (setq N (cons NIL N))) (length N))) > 0.000 sec > -> 1 'append' in such a loop is a lot slower than a straightforward

Re: binding free symbols in a lambda definition

2017-02-10 Thread Joh-Tob Schäg
Why not "(de myf FList (apply (car Flist) (cdr Flist))"? Am 08.02.2017 05:04 schrieb "pd" : > Hello, > > I wonder if there is any way to bind a free symbol in a lambda in order to > pass the lambda to a defined function (for example) > > What I want to do is something

Re: binding free symbols in a lambda definition

2017-02-09 Thread Lindsay John Lawrence
Hi Alex, > However, a function call is about the most expensive thing in PicoLisp. It > interprets the parameter list (X), saves the old value of X, evaluates (not X) > and restores the value of X. (de null..) was really unnecessary here :) I just wrote it for completeness as part of the book

Re: binding free symbols in a lambda definition

2017-02-09 Thread Danilo Kordic
If `and' and `or' is renamed, or just aliased, to `then' and `else', there is little need left for `if' and `cond' >:) . -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Re: binding free symbols in a lambda definition

2017-02-09 Thread Alexander Burger
Hi Lindsay, > I missed to include it... >(de null (X) (not X)) OK! :) However, a function call is about the most expensive thing in PicoLisp. It interprets the parameter list (X), saves the old value of X, evaluates (not X) and restores the value of X. Therefore I would recommend (def

Re: binding free symbols in a lambda definition

2017-02-09 Thread Lindsay John Lawrence
Hi Alex, I missed to include it... (de null (X) (not X)) Thanks! for the suggestions. I tried the pairlis alternatives. Much better. 'extract' will be very useful. I'll have to work with nond a bit more to get how/when use that. /Lindsay On Thu, Feb 9, 2017 at 3:17 AM, Alexander Burger

Re: binding free symbols in a lambda definition

2017-02-09 Thread Lindsay John Lawrence
Picolisp continues to astonish me with its 'Principle of Least Astonishment'... using @ variable arguments is much nicer. /Lindsay # using pairlis2 and sublis from prior email... (de curri2 @ (let (Fun (next) Args (rest) Par (pairlis2 (car Fun) Args) dropP

Re: binding free symbols in a lambda definition

2017-02-09 Thread Alexander Burger
Hi Andrés, thanks for the "curri" examples! > Sorry for the large email and even while pretending to be a clarifying text > it is not :( I think it was :) > Also don't want to give an image of pretending to arrange picolisp's flaw > design, it is absolutely not, not only I don't have the

Re: binding free symbols in a lambda definition

2017-02-09 Thread Lindsay John Lawrence
I've enjoyed the discussion. Curry is a common idiom in the javascript world (my current day job) so it was very interesting to explore it here. Being relatively new to picolisp I have a lot to learn about built-in functionality so exploring these ideas, with feedback from Alex and others more

Re: binding free symbols in a lambda definition

2017-02-09 Thread pd
Sorry for the large email and even while pretending to be a clarifying text it is not :( Also don't want to give an image of pretending to arrange picolisp's flaw design, it is absolutely not, not only I don't have the needed understanding of picolisp nor the knowledge to do so but I consider

Re: binding free symbols in a lambda definition

2017-02-08 Thread pd
Hi Alex > The classical curry in picolisp is what Alex has defined a few emails > > before ;-) > > I never saw a use for the classical curry, so I (ab)used this catchy name > :) > > Can you give an example where it is useful in PicoLisp? > I'm a newbie to picolisp I don't know enough picolisp to

Re: binding free symbols in a lambda definition

2017-02-08 Thread Alexander Burger
On Wed, Feb 08, 2017 at 06:37:17PM +0100, pd wrote: > Picolisp curry function does not follow the pattern, its domain is > completely different and also its image. In other words, you call classical > curry passing it a function argument but you call picolisp curry passing it > several arguments

Re: binding free symbols in a lambda definition

2017-02-08 Thread Erik Gustafson
Ahh, I see what you mean. I was not as familiar with the classical curry, as I was first introduced to the concept through PL. Thanks for clarifying with the great write-up! On Feb 8, 2017 11:45 AM, "pd" wrote: > Thanks for your replies, I think your "subst" is exactly the

Re: binding free symbols in a lambda definition

2017-02-08 Thread pd
Thanks for your replies, I think your "subst" is exactly the same to newlisp "expand" But picolisp curry function doesn't do that, it simply returns a lambda > with 1 parameter having the other one properly substituted with its value > thus making impossible to partially apply the returned

Re: binding free symbols in a lambda definition

2017-02-08 Thread Alexander Burger
On Wed, Feb 08, 2017 at 01:57:22PM +0100, pd wrote: > *I feel* curry to be a unfortunate name for that function because I expect > curry to be a function that once applied to another function with n > parameters it returns a chain of applying functions with exactly one > argument, that is having:

Re: binding free symbols in a lambda definition

2017-02-08 Thread Erik Gustafson
But picolisp curry function doesn't do that, it simply returns a lambda with 1 parameter having the other one properly substituted with its value thus making impossible to partially apply the returned function I still think 'curry' is what you want. Note that 'curry' works with an arbitrary

Re: binding free symbols in a lambda definition

2017-02-08 Thread Erik Gustafson
Hi, If I understand correctly what you said the reason for (let K 3 '(print `K)) returning (print NIL) rather than (print 3) [being K not previously defined] is that the sequence of steps is: Almost, there is a slight confusion in step 2. I would revise it like so: 1- read the whole let

Re: binding free symbols in a lambda definition

2017-02-08 Thread Lindsay John Lawrence
And then there's this... (From "Lisp 1.5 Programmer's Manual".. McCarthy... )... # This function gives the result of substituting the S-expression # x for all occurrences of the atomic symbol y in the S-expression z. (de subst (X Y Z) (cond ((= Y Z) X) ((atom Z) Z) (T (cons

Re: binding free symbols in a lambda definition

2017-02-08 Thread pd
Hi Alex > The key there is the back-quote (`) before the L to force evaluation > > See the doc section on 'Read-Macros' > > http://software-lab.de/doc/ref.html#macro-io > > Exactly. So the whole 'let' expression is read, *then* evaluated. 'L' is > what it > was globally at the time this

Re: binding free symbols in a lambda definition

2017-02-08 Thread pd
On Wed, Feb 8, 2017 at 5:37 AM, Erik Gustafson wrote: > I think 'curry' is what you're looking for. Your 'adder' example could be > written as: > >: (de adder (@N) (curry (@N) (X) (+ X @N))) >-> adder >: (adder 3) >-> ((X) (+ X 3)) >: (doc 'curry)

Re: binding free symbols in a lambda definition

2017-02-08 Thread pd
On Wed, Feb 8, 2017 at 7:15 AM, Lindsay John Lawrence < lawrence.lindsayj...@gmail.com> wrote: > 'fill' (http://software-lab.de/doc/refF.html#fill) does the job in some > cases as well and is a bit easier to read... > > : (de adder (N) (let @X N (fill '((x) (+ x @X) > -> adder > > this is a

Re: binding free symbols in a lambda definition

2017-02-08 Thread Lindsay John Lawrence
Alex, My mistake! In playing with that code, I had defined (setq L 99) shortly before that and forgotten I had done so. Without that, as you pointed out : (de myf (F L) (F L)) -> myf : (let (L 99) (myf '((x) (+ (car x) `L)) (1 2))) -> NIL A good lesson in taking care with scope and current

Re: binding free symbols in a lambda definition

2017-02-07 Thread Alexander Burger
Hi Lindsay, > :(de myf (F L) (F L)) > -> myf > : (let (L 99) (myf '((x) (+ (car x) `L)) (1 2))) > -> 100 I do not think this works. > The key there is the back-quote (`) before the L to force evaluation > See the doc section on 'Read-Macros' > http://software-lab.de/doc/ref.html#macro-io

Re: binding free symbols in a lambda definition

2017-02-07 Thread Lindsay John Lawrence
'fill' (http://software-lab.de/doc/refF.html#fill) does the job in some cases as well and is a bit easier to read... : (de adder (N) (let @X N (fill '((x) (+ x @X) -> adder : (adder 1) -> ((x) (+ x 1)) : (adder 2) -> ((x) (+ x 2)) : ((adder 1) 99) -> 100 /Lindsay

Re: binding free symbols in a lambda definition

2017-02-07 Thread Lindsay John Lawrence
You can also do this... : (de adder (N) (list '(x) (list '+ 'x (eval 'N -> adder : (adder 1) -> ((x) (+ x 1)) : (adder 2) -> ((x) (+ x 2)) : ((adder 99) 1) -> 100 Small examples like this one are great learning devices :) As Erik pointed out though, 'curry' is probably more general purpose

Re: binding free symbols in a lambda definition

2017-02-07 Thread Lindsay John Lawrence
This works: :(de myf (F L) (F L)) -> myf : (let (L 99) (myf '((x) (+ (car x) `L)) (1 2))) -> 100 The key there is the back-quote (`) before the L to force evaluation See the doc section on 'Read-Macros' http://software-lab.de/doc/ref.html#macro-io /Lindsay On Tue, Feb 7, 2017 at 7:55 PM, pd

Re: binding free symbols in a lambda definition

2017-02-07 Thread Erik Gustafson
I think 'curry' is what you're looking for. Your 'adder' example could be written as: : (de adder (@N) (curry (@N) (X) (+ X @N))) -> adder : (adder 3) -> ((X) (+ X 3)) : (doc 'curry) # for more info :) Hope that helps, Erik On Feb 7, 2017 10:04 PM, "pd"