extract analogous to extend?

Pondering the philosophy behind the language
Locked
TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

extract analogous to extend?

Post 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
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: extract analogous to extend?

Post by Lutz »

Can you tell us more about the application problem you want to solve and give code examples?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: extract analogous to extend?

Post 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
> 

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: extract analogous to extend?

Post 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.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

William James
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

Re: extract analogous to extend?

Post 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
Last edited by William James on Wed Mar 07, 2012 9:12 pm, edited 1 time in total.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: extract analogous to extend?

Post 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
(λx. x x) (λx. x x)

William James
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

Re: extract analogous to extend?

Post 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.

Locked