link a list of files?

For the Compleat Fan
Locked
Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

link a list of files?

Post by Sammo »

Will (or should) the following work to extend link.lsp to allow several source files to be specified? I'd like to link several files (one main program plus several libraries) without having to merge the files by hand.

Code: Select all

(load "link.lsp")
(define (link-list orgExe newExeName list-of-SourceNames)
  (set 'tempFileName "linktemp.lsp")
  (set 'tempHandle (open tempFileName "write"))
  (map (fn (F) (write-buffer tempHandle (read-file F))) list-of-SourceNames)
  (close tempHandle)
  (link orgExe NewExeName tempFileName))
after which I would execute

Code: Select all

(link-list "newlisp.exe" "myprog.exe" '("mysource.lsp" "mylibrary.lsp"))
I suppose a macro might be a better implementation choice, but being somewhat "macro challenged" I choose this route. A macro would have the advantage of not having to explictly form the list of files. Any other advantages?

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Hello Sam,

works for me after correcting your typo:

Code: Select all

(link orgExe newExeName tempFileName)
not

Code: Select all

(link orgExe NewExeName tempFileName)
Case-sensitive symbol names in newLISP!
Maybe you could add 'deleting of tempFileName'.

;-)

7:40 am from Germany
Hans-Peter

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

The only advantage, if it is really an advantage, that I can see is that the list of files in

Code: Select all

 (link-list "newlisp.exe" "myprog.exe" '("mysource.lsp" "mylibrary.lsp"))
could be called as

Code: Select all

 (link-list "newlisp.exe" "myprog.exe" "mysource.lsp" "mylibrary.lsp")
Using the code you have, I think the macro would be something like

Code: Select all

(define-macro (link-list orgExe newExeName )
  (set 'tempFileName "linktemp.lsp")
  (set 'tempHandle (open tempFileName "write"))
  (map (fn (F) (write-buffer tempHandle (read-file F))) (args))
  (close tempHandle)
  (link orgExe newExeName tempFileName))
Eddie

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

Post by Lutz »

you would have to do (slice (args) 2) because the first two parameters are the orginal and new exe.

Lutz

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Oops!

Eddie

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Nice! Shorter is better!
Hans-Peter

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

Post by Sammo »

Thanks, everyone! Here is the working macro version:

Code: Select all

(load "link.lsp")
(define-macro (link-list orgExe newExeName ) 
    (set 'tempFileName "linktemp.lsp") 
    (set 'tempHandle (open tempFileName "write")) 
    (map (fn (F) (write-buffer tempHandle (read-file F))) (slice (args) 2)) 
    (close tempHandle) 
    (link orgExe newExeName tempFileName)
    (delete-file tempFileName))
which is called like this:

Code: Select all

(link-list "newlisp.exe" "myprog.exe" "main.lsp" "lib.lsp" "etc.lsp")

Locked