Changes in newLISP v.10.0 (previous init.lsp)

Started by cormullion, September 05, 2008, 08:32:55 AM

Previous topic - Next topic

cormullion

Can't remember if I asked this before...



It would be great if newLISP would load a local ~/.init.lsp file even if there's no /usr/share/newlisp/init.lsp. It seems that some newlisp installers (or re-installations) revert back to having just an 'init.lsp.example' file which doesn't get loaded, and therefore doesn't load any other init.lsp.



Or you could have the /usr/share/newlisp/init.lsp always exist, but contain only this code uncommented:


(constant (global '$HOME) (or (env "HOME") (env "USERPROFILE") (env "DOCUMENT_ROOT")))
(if $HOME (catch (load (append $HOME "/.init.lsp")) 'error))


Part of the reason for this is that making changes to the /usr/share/newlisp directory requires authority... I can't make changes to this directory myself, on some systems (eg my nearlyfreespeech.net sites. So I can't run any init code.

xytroxon

#1
Can you use the link.lsp util?



link.lsp

----

;; the new executable file will not load init.lsp but

;; the appended file instead

___



The appended file code could then look for and load your init.lsp...



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

Lutz

#2
The next version of newLISP will try to load both: first the init.lsp in the install directory and second the home directory .init.lsp file.

Jeff

#3
You should make it check the home directory first.  If it finds it, it then stops.  If it does not, it goes for the global, but only if there is nothing in the home directory.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#4
Either option would be great! Thanks for considering this, Lutz.

Lutz

#5
It will be as in Jeff's proposal. Having your own $HOME/.init.lsp then lets you completely bypass system wide setting in case you don't want them. This will work in Windows too using the USER_PROFILE environment variable.



And here the big surprise: in the next generation of newLISP (version 10 and after) you can handle references returned from built-in functions:


(set 'L '(a b c d e f g))

(setq (L 3) 'D)
(setq (first L) 'A)

D => (A b c D e f g)

; or

(set 'A '((a 1) (b 2) (c 3)))

(setq (assoc 'b A) '(b 222))

A => ((a 1) (b 222) (c 3))

; or

(push 4 (assoc 'c A) -1)

A => ((a 1) (b 222) (c 3 4))

; or

(set 'L '(w e v f b t))

(pop (sort L)) => b

L => (e f t v w)

; another one

(set 'L '((a 1) (b 1 (2 3) 4) (c 3)))

(push 99 (lookup 'b L -2))

L => ((a 1) (b 1 (99 2 3) 4) (c 3))

... etc ...


This type of handling list or array references is usual in most programming languages. Many newbies to newLISP are trying this intuitively at first.



Changes for this also significantly speed up handling of bigger lists and arrays, decrease memory usage and obsolete several of the destructive setter-functions now in use.



Most important its makes newLISP easier to learn and use.

cormullion

#6
Cool! I think!

Jeff

#7
Will that be released anytime soon?  I like setf :)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Kazimir Majorinc

#8
This looks great to me, especially set looks more abstract and easier to use.



(set 'L '(w e v f b t))

(pop (sort L)) => b

L => (e f t v w)


It is certainly better - if one wants to "pop" copy of the sorted value of L, he can make the copy explicitly. How do you plan to accomplish that? Is it change in interpreter or specifically in functions sort or pop?
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Lutz

#9
QuoteIs it change in interpreter or specifically in functions sort or pop?


It is both, changes in newLISP's core routines processing expressions and changes in built-in functions. Its a type of optimization of ORO memory management, before made only for set, but now available system wide.



All built-in functions when returning lists or arrays bound to symbols or part of those lists or arrays, now return references instead of copies.



This affects the following functions:



assoc

first

last

lookup

nth

replace

reverse

rotate

set  (returned reference already)

setf (new function)

setq (old function now working like setf)

set-ref

set-ref-all

sort

swap



and this also effect all control structures, which don't maintain local variables:



begin

if

if-not

cond

case

when

unless

while

until

do-while

do-until



this means you cannot use 'begin' any more to make destructive function non-destructive, you will now use something like (define (copy x) x) and then do: (sort (copy mylist)) to make the sort non-destructive.



Reference-returns together with the new 'setf' make it convenient to change lists and arrays:



(set 'lst '(a b c d))

(setf (last lst) 99)

lst => (a b c 99)



The normal old 'set' has not changed (it always returned a reference, but nobody was aware of it). 'setq' now points to 'setf' internally. I opted to keep both functions, to make it easier for converts from other Lisps. Many have 'setq' and 'setf' and want to keep on using them as they did before. It also improves readability and understandability of code having both.



Version 9.9.2 (a precursor to newLISP v.10.0) is ready, but I am still working on documentation changes. This version will be posted latest on Monday, perhaps earlier.



Although  most old code is compatible with the new generation of newLISP, I opted of jumping from version 9 to 10, because the changes mark a new style of programming in newLISP which is closer to other programming languages and more intuitive.



As before user defined lambda function will return copies and copy parameters (except when using default functors).

DrDave

#10
EDIT



Nevermind... I see that in the post above Lutz already sorted it out for me with the remarks about returning copies versus references.

======================================



I tried this as the separate opertions with v9.4.8

(set 'L '(w e v f b t))
=> (w e v f b t)

(sort L)
=> (b e f t v w)

(pop L)
=> b

L
=> (e f t v w)

So both sort and pop were destructive as expected.



But combing thus:
(set 'L '(w e v f b t))
=> (w e v f b t)

(pop (sort L))
=> b

L
=> (b e f t v w)


I see that the proposal will be for the the combined functions to give the same final list that the separate functions give. So, I am wondering why currently pop is destructive when used alone, but is not destructive when combined in an expression. Is it because sort did its thing and sent a copy of its result rather than its original for pop to work on?
...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

cormullion

#11
Quote from: "Lutz"Although  most old code is compatible with the new generation of newLISP,


I don't understand the changes yet (need to take my time) ... But for the executive summary - what code will stop working at version 10?

Lutz

#12
In all of the code shipped with newLISP, from 55 lisp files, only 3 files needed minor edits. Applications newlisp-wiki and newlisp-ide on the newlisp.org web-site did not require any changes. Most of the changes where due to dropping 'set-nth', 'nth-set', 'set-assoc', 'assoc-set' in favor of the new 'setf' which can do them all in combination with 'nth' or 'assoc'.



A quick scan of "Introduction to newLISP" shows that there are basically only two areas of change, and I can help to correct the examples. The following is already about 80% of it.



'set-nth', and 'nth-set' are substituted by 'setf' in combination with nth:



; the old
(set-nth 5 data 0)

; gets now
(setf (nth 5 data) 0)
; or
(setf (data 5) 0)

; the old
(nth-set 5 data "")

;gets now
(setf (nth 5 data) "")
; or
(setf (data 5) "")


There are two or three more like this.



'set-assoc' ans 'assoc-set' are subbstitued by 'setf' in combination with 'assoc':


; the old
(assoc-set (table charge)  (list charge (+ result 1)))

; gets now
(setf (assoc charge table)  (list charge (+ result 1)))

; and this
(set-assoc (sol-sys "Jupiter") '("Jupiter" 11.2 ... 64))

; gets now
(setf (assoc "Jupiter" sol-sys) '("Jupiter" 11.2 ... 64))


May be and additonal short chapter about 'setf' or may be just use/introduce 'setf' in the part of the introduction where you explain how to modify lists and arrays. Those are the parts I corrected the examples above. The changes make the code faster in most instances and always save memory.



There are no changes required in your new time module.



I will go through the introduction at a later time again to see if some of the code could be written more elegantly and efficiently using reference-returns possible now. The fact that many built-in functions now return references will typically not disturb any previously written code, just give the programmer more expressiveness for future programs written.



There will also be a short "conversion guide" with the final 10.0 release. Most of it is already written on this post. But there is also beloved 'unless' reintroduced without the else clause, and thats pretty much all of it :-)

cormullion

#13
Thanks for the attention to detail, Lutz... I'm not too worried about the tutorial document yet (only just finished a revision... :).



Did you really mean you are


Quotedropping 'set-nth', 'nth-set', 'set-assoc', 'assoc-set'


or just providing improved functions and leaving the existing ones in? (I hope the latter - why do you have to drop them?)



Perhaps this important topic should be moved to a sticky topic...?

Kazimir Majorinc

#14
Quote from: "cormullion"Did you really mean you are


Quotedropping 'set-nth', 'nth-set', 'set-assoc', 'assoc-set'


or just providing improved functions and leaving the existing ones in? (I hope the latter - why do you have to drop them?)


I believe he'll leave these for a decent time, however, your main problem (because you have lot of code) is that code like



(pop (sort L))



will silently change behaviour. So, you'll maybe have to "port" your programs if you want to use them with new versions of Newlisp. To replace "sort" with "copy-sort" you'll write etc. It might look ugly on the first sight, but it is not that bad really; back in 1970's almost never happened that two computers or two generations of compiler accepted same source code.  Day or two of job maybe.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.