((a b c) (1 2 3)) => ((a 1) (b 2) (c 3)) (parallel lists to

Started by TedWalther, November 03, 2009, 02:07:54 PM

Previous topic - Next topic

TedWalther

What is the fastest/cleanest way to do this in newlisp?



((a b c) (1 2 3)) => ((a 1) (b 2) (c 3))


I'd like to convert some parallel lists to association lists. I know I can do it with a simple doloop.  I just have a nagging feeling that there has to be a simpler, more built-in way to do it.



Also, I find it annoying that newlisp symbols aren't required to be separated by brackets or spaces.  I'd like to do this:



(1+ x)
(1- x)


And I chose those forms because I understand that implicit indexing makes the following two forms impossible:



(-1 x)
(+1 x)


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.

Kazimir Majorinc

Perhaps this one.



(transpose '((a b c)(1 2 3))) => ((a 1) (b 2) (c 3))



I didn't quite understood the second note.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

TedWalther

Thank you Kazimir!  I had a hunch there was something in the matrix stuff that would do it since it is a vector type operation.  To give more clarity on the other stuff:



(1+ x) => (+ x 1)
(1- x) => (- x 1)


That is what I'd like to define as functions.  Wonder if the new macro stuff would allow it?  This touches on how symbols are parsed in newlisp; 1 and - are counted as separate symbols instead of being considered as one symbol 1-



Also, while I'm at it, it is getting annoying, the fact that inc coerces everything to float.  If I am dealing with ints, incrementing an int by an int, how does it make sense to cast it to float?



Why should this yield a float?



(setq f 1)
(inc f 2)
=> 3.0
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

Making a macro for 1+ or 1- would not work (*), because newLISP's parser will take 1+ as two tokens 1 and +, and in +1 -1 the parser will take the sign as a prefix to the number,  but here is a macro for incrementing without coercion to float:





(macro (+= X Y) (setq X (+ X Y)))
(set 'x 12)

(+= x 2) => 14


(*) you still could make it work by writing a different macro.lsp module, the current one always looks for an undefined identifier has the first token, but you could write that differently.

TedWalther

Thanks Lutz. I guess I'll have to define plus1 and minus1 to do what I want.



Can you enlighten me a little about your rationale for doing parsing the way you are?  Is there a reason to not have atoms delimited solely by whitespace and brackets?  Was it for allowing code compacting in shipping applications?



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.

Kazimir Majorinc

You can use Roman numbers.



+I, -I, I+, I-



Define all four so you'll not have to remember which one you defined, +I or I+.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.