| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi all, First off, I'm a Scheme newbe. I am looking for an unlist-function which workings should be made clear from the following example: > (+ (unlist (list 1 2 3))) 6 Of course, this is not where I want to use it for. When you have a function that looks like this: (define (f . x) <function body>) You can pass to f any number of arguments you like, which is then results as the list x of arguments in the function body. But now I would like to do something with the x to get another list y, and call f with the elements of y as arguments. Thus (define (f . x) <generate list y from x> (f (unlist y))) Does such a function exist? Thanks in advantage, Koen |
|
#2
| |||
| |||
| Koen <koenvanwoerdennews@gmail.com> wrote: > (define (f . x) > <generate list y from x> > (f (unlist y))) You are looking for APPLY: (define (f . x) ; generate y from x (apply f y)) -- Nils M Holm <n m h @ t 3 x . o r g> -- http://t3x.org/nmh/ |
|
#3
| |||
| |||
| apply |
|
#4
| |||
| |||
| Koen <koenvanwoerdennews@gmail.com> writes: > Hi all, > First off, I'm a Scheme newbe. > I am looking for an unlist-function which workings should be made > clear from the following example: > >> (+ (unlist (list 1 2 3))) > 6 (apply + (list 1 2 3)) You should read the 50 pages of the R5RS report. It could hardly be shorter... -- __Pascal Bourguignon__ http://www.informatimago.com/ "This statement is false." In Lisp: (defun Q () (eq nil (Q))) |
|
#5
| |||
| |||
| Hi again, Nils M Holm wrote: > Koen <koenvanwoerdennews@gmail.com> wrote: >> (define (f . x) >> <generate list y from x> >> (f (unlist y))) > > You are looking for APPLY: > > (define (f . x) > ; generate y from x > (apply f y)) > That's it, thanks. ![]() Koen |
|
#6
| |||
| |||
| > You should read the 50 pages of the R5RS report. *It could hardly be > shorter... If you skip the chapter '7. Formal syntax and semantics' and the index, it is only 37 pages! ![]() But seriously, R5RS is worth a read. It is short and sweet. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.