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
Perhaps this one.
(transpose '((a b c)(1 2 3))) => ((a 1) (b 2) (c 3))
I didn't quite understood the second note.
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
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.
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
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+.