Newbe question: unlist-function

This is a discussion on Newbe question: unlist-function within the Scheme forums in Programming Languages category; 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, ...

Go Back   Application Development Forum > Programming Languages > Scheme

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-13-2008, 01:40 PM
Koen
Guest
 
Default Newbe question: unlist-function

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
Reply With Quote
  #2  
Old 08-13-2008, 01:55 PM
Nils M Holm
Guest
 
Default Re: Newbe question: unlist-function

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/
Reply With Quote
  #3  
Old 08-13-2008, 01:55 PM
Grant Rettke
Guest
 
Default Re: Newbe question: unlist-function

apply
Reply With Quote
  #4  
Old 08-13-2008, 02:15 PM
Pascal J. Bourguignon
Guest
 
Default Re: Newbe question: unlist-function

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)))
Reply With Quote
  #5  
Old 08-13-2008, 02:24 PM
Koen
Guest
 
Default Re: Newbe question: unlist-function

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
Reply With Quote
  #6  
Old 08-13-2008, 05:34 PM
Grant Rettke
Guest
 
Default Re: Newbe question: unlist-function

> 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.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:29 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.