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 - mark5009

#1
newLISP in the real world / conditional compilation?
March 02, 2017, 08:35:51 PM
Hi.



Running under OSX/Unix, I like to first test my code with a #! , then compile them with a -x for use.  So,



$ cat foo.lsp
#! /usr/bin/env newlisp
(println "args -> " (main-args))
(exit)
$ ./foo.lsp bob
args -> ("newlisp" "./foo.lsp" "bob")
$ newlisp -x foo.lsp foo
$ ./foo bob
args -> ("./foo" "bob")


If I want that first arg, it has gone from position 2 to position 1 in the args.  



My question is the obvious one: is there a way I can get around this behavior?  Use a condition compile flag?  Or is there a better solution than editing the file each time I want to compile it?



Thanks in advance .. mark
#2
I have been enjoying using NL in what I do.  Part of that is to create lots of little scripts to do simple tasks (calculate this, work out that) under various unix platforms (incl OSX).  Nothing sophisticated, just useful.  So, to help fellow newbies along I thought I'd share the basic template I use.  Nothing magic or interesting, just lets me make the scripts easy to use in a unix-like environment.  I modify it to use the arguments I need, the functions I want, and so on.



Hack it as you like.



 .. m.



#!/usr/bin/newlisp
;;
;; simple template for new-lisp scripts
;;

;; -----------------( boiler-plate )-----
;;
(constant 'APPNAME (main-args 1))

(define (help-msg)
  (println "usage: " APPNAME " <mand-n> [opt-x]"))
 
(define (argc)
  (length (main-args)))

;; -----------------( app-specifics )-----
;;
(define (do-stuff n)
    (println " ( " n " ) "))

;; -----------------( main-driver )-----
;;
(setq n-args (argc))
(case n-args
  (3    (do-stuff (int (main-args 2))))
  (true
    (help-msg)))
         
(exit) ; important
#3
I generally just use the #! syntax



$ cat foo.lsp
#!/usr/bin/newlisp

(println (main-args))
(exit)

$ chmod 755 foo.lsp    # make sure foo.lsp is executable
$ ./foo.lsp xxxx.file
("/usr/bin/newlisp" "./foo.lsp" "xxxx.file")


Hope this helps.



 .. m.
#4
newLISP in the real world / Re: (newbie) Listiness
October 26, 2014, 04:09:47 PM
Thanks, guys!  That is most helpful.



 .. mark.
#5
newLISP in the real world / Re: (newbie) Listiness
October 25, 2014, 06:57:38 PM
Thanks for your reply, bairui.  My problem is I am not being very clear.



Here is the real issue.  Say I have a file I want to read:



# stuff to ignore
123:avc
234:vvc
# more to ignore and the following blank line as well

# and there is the last stuff
999:xxc


I want to end up with something like:



> (set 'foo-file "/tmp/foo.tmp")
> (set 'contents (slurp-in-file foo-file)

> contents
((123 "avc")(243 "vvc")(999 "xxc"))


Basically your typical read-in-a-file scenario for sysadmin work.

I am just not sure of the syntax involved in going through the file

a line at a time, throwing away the crud, then parsing the line.

I know newlisp can do it because I can make each part do its thing.

It is just the putting it all together that I am having a problem with.



TIA, mark.
#6
newLISP in the real world / (newbie) Listiness
October 24, 2014, 11:40:52 PM
Hi.  Newbie here.  I am trying to understand what is happening here.  



My expectation is that bar should contain (() 1 2 3 4 5) (which is what

I am after, but it doesn't.  Can someone fill me in on where my thinking

is a little broken?  I want to construct a list of the individual items of

foo in bar.



Thanks .. mark.



> (set 'foo '(1 2 3 4 5))
(1 2 3 4 5)
> (set 'bar (cons))
()
> (dolist (it foo) (println it))
1
2
3
4
5
5
> (dolist (it foo) (list bar it))
(() 5)