newLISP Fan Club

Forum => newLISP newS => Topic started by: Kazimir Majorinc on October 11, 2008, 04:35:36 PM

Title: Two small proposals for v10!
Post by: Kazimir Majorinc on October 11, 2008, 04:35:36 PM
(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;[/color]



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.
Title:
Post by: Fanda on October 12, 2008, 03:11:27 AM
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:
> (dup 'a 5)
(a a a a a)
> (dup "a" 5)
"aaaaa"

In my opinion, it would be nice if 'dup' always returned a list. If string is needed, use 'join':
> (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?):
> (apply list '(a b c d) 2)
(((a b) c) d)

More readable would be to introduce new function 'reduce' - works as (apply op list 2):
> (reduce list '(a b c d))
(((a b) c) d)
> (reduce list 'init '(a b c d))
((((init a) b) c) d)


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.
Title:
Post by: DrDave on October 12, 2008, 04:48:19 AM
Fanda,



What is it that dont you like about using
> (apply list '(a b c d) 2)

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
(apply list '(a b c d e f g h) 3)
=>((((a b c) d e) f g) h)


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.
Title:
Post by: Fanda on October 12, 2008, 04:57:32 AM
Quote from: "DrDave"What is it that dont you like about using
> (apply list '(a b c d) 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.



Fanda
Title:
Post by: Lutz on October 12, 2008, 05:12:23 AM
'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:


> (dup "a" 5 true)
("a" "a" "a" "a" "a")
>


The reduce parameter in 'apply' will be fixed and posted later as 9.9.8.