Suggestions

For the Compleat Fan
Locked
Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Suggestions

Post by Fanda »

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

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post by Sammo »

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

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

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

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Locked