newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Fanda on October 15, 2005, 01:53:48 PM

Title: Suggestions
Post by: Fanda on October 15, 2005, 01:53:48 PM
1) How do I append list to the list?

> (setq x '(1 2))

(1 2)

> (setq x (append x '(3 4)))

(1 2 3 4)



In this case, 'push' cannot be used:

> (push '(3 4) x -1)

(3 4)

> x

(1 2 (3 4))

>



Function 'write-buffer' accepts only file (integer) or string. Could we add appending to the lists?



Thank you, Fanda
Title:
Post by: Sammo on October 15, 2005, 02:37:49 PM
> (setq x '(1 2))

(1 2)

> (setq x (cons x '(3 4)))

((1 2) 3 4)

> x

((1 2) 3 4)
Title:
Post by: Fanda on October 15, 2005, 05:45:47 PM
Let me explain more:

I mean destructive function (like push) that would add (append) elements to the list from inside of other list.



> (setq x '(1 2))

(1 2)



new write-buffer or other function: (write-buffer x '(3 4))

> x

(1 2 3 4)



Fanda
Title:
Post by: Fanda on October 17, 2005, 11:09:49 AM
I thought, I might needed it in recursive functions, but (append) will work fine, I guess ;-)

Lutz - do you have any comments to 1) ?



2) Could we add the 'int?' function?

> integer

integer <417ED0>

> int

int <417ED0>

> integer?

integer? <40BC50>

> int?

nil

>



3) I also noticed that we don't have function for rounding numbers:

I am suggesting: (round x [n]) -- x = int/float -- n = int (float?)

(round 1.9) => 2

(round 123.48) => 123

(round 123.48 0) => 123

(round 123.48 1) => 120

(round 123.48 2) => 100

(round 123.48 3) => 0

(round 123.48 -1) => 123.5



Fanda
Title:
Post by: Lutz on October 17, 2005, 05:47:38 PM
I want to keep the predicates 'integer?' and 'symbol?' in the long form so they are easier to distinguish from the 'int' and 'sym' functions.



For rounding numbers just try to use 'format' which will do it for you when displaying numbers:



(format "%0.2f" 1.235) => "1.24"



Lutz