(1) Aliases +., -., *., /., %. beside/later instead of add sub mul etc. It has some advantages.
(2) Functions println=, print= such that (print= x (+ 2 4) y) produces following output:
x=nil; (+ 2 4)=6; y=nil;
It is not big deal but is useful in "scripting style", for some small programs of the kind we publish on this forum. I also have more "Lispy" version (-> x nil) (-> (+ 2 4) 6) ... but I rarely use it.
These two are in my library, and they are trivial to implement, but I thought it might be of interest out of the box.
Two small proposals for v10!
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
Hello newlispers!
Since there is gonna be a new newLISP version, which makes some breaking changes, it is a good time to introduce new things and do some cleanup :-)
I am proposing to change behavior of 'dup'. Currently:
In my opinion, it would be nice if 'dup' always returned a list. If string is needed, use 'join':
Another, IMO confusing behavior, is overloaded apply (currently doesn't work?):
More readable would be to introduce new function 'reduce' - works as (apply op list 2):
Greetings, Frantisek
PS: Yes, I am still using newLISP :-) I use it at work to parse text files and at home to generate web pages. It is also a nice calculator, if you need to do some numerical calculations.
Since there is gonna be a new newLISP version, which makes some breaking changes, it is a good time to introduce new things and do some cleanup :-)
I am proposing to change behavior of 'dup'. Currently:
Code: Select all
> (dup 'a 5)
(a a a a a)
> (dup "a" 5)
"aaaaa"
Code: Select all
> (dup 'a 5)
(a a a a a)
> (dup "a" 5)
("a" "a" "a" "a" "a")
> (join (dup "a" 5))
"aaaaa"
Another, IMO confusing behavior, is overloaded apply (currently doesn't work?):
Code: Select all
> (apply list '(a b c d) 2)
(((a b) c) d)
Code: Select all
> (reduce list '(a b c d))
(((a b) c) d)
> (reduce list 'init '(a b c d))
((((init a) b) c) d)
PS: Yes, I am still using newLISP :-) I use it at work to parse text files and at home to generate web pages. It is also a nice calculator, if you need to do some numerical calculations.
Fanda,
What is it that dont you like about using
It did just as it says: It creates a two-membered list on each 'apply', resulting in nestings of two-membered lists.
Maybe you can see it better using a longer list grouped in threes.
Try
You can see when it reached 'h' that there was not enough members left to append two of them, so the final grouping has just two members instead of three.
What is it that dont you like about using
Code: Select all
> (apply list '(a b c d) 2)
Maybe you can see it better using a longer list grouped in threes.
Try
Code: Select all
(apply list '(a b c d e f g h) 3)
=>((((a b c) d e) f g) h)
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2
"Getting Started with Erlang" version 5.6.2
It combines two different concepts - applying and reducing. When I read the code, I need to count how many parameters 'apply' function has to decipher what action is being taken. That can be confusing. Separate function for reducing would be IMHO better.DrDave wrote:What is it that dont you like about usingCode: Select all
> (apply list '(a b c d) 2)
Fanda
'dup' on strings is mostly used for concatenation to create string fields, e.g. to create blank fields, lines etc. or with binary zeros to reserve buffers passed to imported functions.
Use the extra boolean flag to force a list:
The reduce parameter in 'apply' will be fixed and posted later as 9.9.8.
Use the extra boolean flag to force a list:
Code: Select all
> (dup "a" 5 true)
("a" "a" "a" "a" "a")
>