[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: unpacking a list
From: |
David Kastrup |
Subject: |
Re: unpacking a list |
Date: |
Sat, 28 Nov 2015 09:40:41 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Urs Liska <address@hidden> writes:
> Hi all,
>
> I don't seem to find a way to "unpack" a list. I think I won't explain
> the background, but basically what I need is that
> (list (list 1 2 3) 4)
> becomes
> (list 1 2 3 4)
>
> This is a mock-up of my real code:
>
> #(define (func-a)
> (list 1 2 3))
>
> #(define (func-b)
> (list
> (func-a)
> 4))
>
> #(display (func-b))
>
> What I need is that the call to (func-a) doesn't evaluate to a list but
> to its elements.
> I have "solved" it by actually using something like
> (append (func-a) (list f4))
> but I think that's not really clean.
It most definitely _is_ clean.
> I'd prefer directly "unpacking" the list in situ.
>
> Any suggestions?
You can write
#(define (func-b)
`(,@(func-a) 4))
but this will not result in anything significantly different in the
ultimate code.
You can also write a generic unpacker like
#(define (list-elts x)
(cond ((null? x) x)
((pair? x) (append! (list-elts (car x)) (list-elts (cdr x))))
(else (list x))))
And then use something like (list-elts (cons (func-a) 4))
But that in no way is cleaner than the call to append when you know your
original structures anyway.
--
David Kastrup
- unpacking a list, Urs Liska, 2015/11/28
- Re: unpacking a list,
David Kastrup <=
- Re: unpacking a list, Urs Liska, 2015/11/28
- Re: unpacking a list, David Kastrup, 2015/11/28
- Re: unpacking a list, Urs Liska, 2015/11/30
- Re: unpacking a list, Urs Liska, 2015/11/30
- Re: unpacking a list, David Kastrup, 2015/11/30
- Re: unpacking a list, Urs Liska, 2015/11/30
- Re: unpacking a list, David Kastrup, 2015/11/30
- Re: unpacking a list, Urs Liska, 2015/11/30