Page 1 of 1

extract analogous to extend?

Posted: Thu Feb 09, 2012 6:07 am
by TedWalther
I was just trying to use "pop" to pop several items off the front of a list. I'm making a MIDI debugger. I've been very happy with the ease that newLISP has allowed for bit-banging this serial protocol.

My only gripe so far is that there is no equivalent to "pop" that lets me take multiple elements from a list. How about "extract" that is like "slice", but destructive like "extend"? Or some boolean flag to slice?

That, and bind wants the variables in the association list to all have names that begin with Uppercase. That is annoying. I note that the examples in the manual don't require this. Am I doing something wrong? Bind+unify is very cool, but the Title-case requirement is a boner-killer. Otherwise, a syntax like (setq '(a b c d) (some-function)) would be nice. Similarly with the let family. Or is this something where I am supposed to use macro wizardry by diving into my copy of Paul Graham's "On Lisp" and translating to newLISP?

Ted

Re: extract analogous to extend?

Posted: Thu Feb 09, 2012 5:45 pm
by Lutz
Can you tell us more about the application problem you want to solve and give code examples?

Re: extract analogous to extend?

Posted: Fri Feb 10, 2012 3:17 pm
by Lutz
... also it is not true that 'bind' wants variables in title-case. Title-case is only required for variables in 'unify'.

Code: Select all

> (bind '((a 1) (b 2)))
2
> a
1
> b
2
> 
regarding your '(setq '(a b c d) (some-function))' snipped, perhaps you mean this:

Code: Select all

> (map set '(a b c) '(1 2 3))
(1 2 3)
> a
1
> b
2
> c
3
> 

Re: extract analogous to extend?

Posted: Sat Feb 11, 2012 5:59 pm
by TedWalther
Yes, you are right, it is unify that wants title-case. I feel foolish now; thanks for the map-set example. That is what I wanted.

Re: extract analogous to extend?

Posted: Wed Mar 07, 2012 10:12 am
by William James
I never thought of

Code: Select all

(map set '(a b c) '(1 2 3))
... probably because it's not allowed in other languages.

Gambit Scheme:

Code: Select all

4> (map define '(ee ff gg) '(22 33 44))
*** ERROR IN (console)@8.6 -- Macro name can't be used as a variable: define

Re: extract analogous to extend?

Posted: Wed Mar 07, 2012 8:38 pm
by rickyboy
Don't know about Scheme, but in SBCL:

Code: Select all

* (mapc #'set '(ee ff gg) '(22 33 44))
(EE FF GG)
* ee
22
* ff
33
* gg
44

Re: extract analogous to extend?

Posted: Wed Mar 07, 2012 9:13 pm
by William James
rickyboy wrote:Don't know about Scheme, but in SBCL:

Code: Select all

* (mapc #'set '(ee ff gg) '(22 33 44))
(EE FF GG)
* ee
22
* ff
33
* gg
44
Yes, I later realized that. My post has been corrected.