Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Bat

#1
newLISP in the real world /
November 09, 2003, 06:22:51 PM
That does it, you're right

Where do you get your time from ? Are your days -as ours- 24-h long ?



(dotimes (x 1000) (print-pretty '(thanks again)))
#2
newLISP in the real world /
November 08, 2003, 06:51:38 AM
I personally prefer that no breaklines are introduced without my control.  You see, if I print a datase to a file one register a line, then when I read the file with read-line, I'm sure I get a whole register, otherwise its awkward.



Maybe you're right that it should be left as an option to break lines when printing to files. Since print implements nicely this with "n" "r".



Another possible way is to leave print as it is, and wrk out a nice (pretty-print) function to allow for all this problems.
#3
Just two more quests (by now !):

1. Is it possible to use optional arguments in functions, other than through 'define-macro' ?  I dont quite get it clear from the manual. It looks fine anyway, since a variable-number-of-args function is certainly a strange concept itself... not very 'mathematical' to say least.





2.Why is line length limited to 64 chars for print and println ?  This limitation occurs also when printing to files, and looks odd.
#4
newLISP in the real world / Strange behaviour of push
November 05, 2003, 03:30:02 PM
The correct code is:



(set 'people

'((p1 (name (john macy)) (age 45) (hobbies fishing reading jogging))

(p2 (name (mary dickens)) (age 27) (hobbies knitting dancing watching-tv))

(p3 (name (paul donkey)) (age 18) (hobbies kicking eating))))



(define (insert value field-id register-id relation , register field new-field new-register)

(set 'register (assoc register-id relation))

(set 'field (assoc field-id register))

(set 'new-field (cons (first field) (cons value (rest field)))) ; <-- here try push !

(set 'new-register (replace-assoc field-id register new-field))

(replace-assoc register-id relation new-register))



And it is called with:



(insert 'drinking 'hobbies 'p2 people)



The problem is when substitute "(push value field 1)" for

"(cons (first field) (cons value (rest field)))"



Why push does not work ?
#5
newLISP in the real world / Strange behaviour of (push )
November 05, 2003, 03:04:15 PM
I have a database organised as association lists (relations) of registers, one for each individual, and each register itself contains an association list of pairs <field value>. So, for example, it would be:

(set 'people

'(p1 (name (john macy)) (age 45) (hobbies fishing reading jogging))

 (p2 (name (mary dickens)) (age 27) (hobbies knitting dancing watching-tv))

 (p3 (name (paul donkey)) (age 18) (hobbies kicking eating)))



Now, I need to be able to insert a value into the some field, for some person-register:



(define (insert value field-id register-id relation , register field new-field new-register)

  (set 'register (assoc register-id relation))

  (set 'field (assoc field-id register))

  (set 'new-field (push value field 1))                                  

  (set 'new-register (replace-assoc field-id register new-field))

  (replace-assoc register-id relation new-register))



It responds with an error message "list expected in function replace-assoc". It seems that 'push' does not return a list. (It makes no difference to use or not the second argument to push; it always returns the atom <value>.



When I replace '(push value field 1)' for '(cons (first field) (cons value (rest field)))' it works smoothly.



Any suggestions ?

BTW, how would you code it ?
#6
newLISP in the real world / Problem with gammai
October 22, 2003, 04:51:55 PM
When calling (gammai n m) with n=0 (not the right thing to do, but can happen) my computer crashes badly. I must make a hard reset.  OS: Windows XP. Pentium III.

Maybe some error trapping would do well.
#7
newLISP in the real world /
October 10, 2003, 09:31:14 AM
And not necessary to open a new thread each time !

You can delete this thread ;-)
#8
newLISP in the real world / Sorry, 'tis easy !
October 10, 2003, 09:28:31 AM
Of course, you parse the string and map 'symbol onto it:



(map symbol (parse "hi how are you")) -> (hi how are you )



Apologies

The parsing capabilities of Newlisp do much of the work, and so much simpler .
#9
newLISP in the real world / More on reading
October 10, 2003, 09:18:52 AM
I Common Lisp you can transform a string into a list of atoms, such as:

"hi how are you" -> (hi how are you).

You just 'read-input-from-string' the original string and cons the atoms into a list.  For instance, see (read-sentence) in Winston 3rd ed., p. 426.



How to do this in Newlisp ?

I imagine this can be done with regex, but since I dont know Perl, I cannot be sure.
#10
newLISP in the real world / How about (read) ?
October 10, 2003, 08:52:29 AM
How can you do reading of regular Lisp expressions, in the way that CL does it with (read) ?  Especially to read from files, its useful to be able to read a whole expression -enclosed in parentheses-. Maybe I've missed it somewhere ?  In fact, load must use such a function, so it cannot be difficult.



Also, there are some minor typos in the manual. For instance, in the random syntax definition of 'random', the scale and the offset appear to be swapped over.