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

#16
@TedWalther



Thanks for the getopts.lsp module, Ted. Here is a macro for combining the definition of short and long options into a single call. The aim here is to DRY up option specification. My newLISP-fu in general and macro-fu in particular is not strong, so please elucidate any boo-boos.


;; @syntax (opt <short-opts> <long-opt> <action> <arg?> <desc>)
;; @param <short-opts> The single letter option(s)
;; @param <long-opt> The long option
;; @param <action> The code to execute when the option is found
;; @param <arg?> 'nil' if the option doesn't take an argument, otherwise a string that describes the type of argument the option takes.
;; @param <desc> A string that describes the option.  This is used by the 'usage' function.
;; @example
;; (opt "?h" "help" (getopts:usage) nil "Print this help message")
;; ...
;; $ ./myscript.lsp -h
;; $ ./myscript.lsp -?
;; $ ./myscript.lsp --help
(define-macro (opt short-opts long-opt action arg? desc)
              (dolist (opt (explode short-opts))
                (eval (list 'shortopt opt action arg? desc)))
              (eval (list 'longopt long-opt action arg? desc)))


Also... I'm looking forward to seeing hartrock's contribution to bundle the options together in the getopts:usage output being added to the module.



Cheers,

Barry.
#17
newLISP newS / Re: newLISP in a browser
January 02, 2014, 02:38:16 PM
You're tireless, Lutz! Awesome.

newLISP deserves a lot more attention; perhaps this move to the browser will help?



One thought I just had for this is to convert the newLISP manual example code segments into embedded, runable, modifiable, interactive learning tools.
#18
Newlisp's (F)OOP Inheritance:


(new Class 'Person)
(define (Person:name) (self 1))
(define (Person:salary) 0)

(new Person 'Worker)
(define (Worker:salary) (self 2))

(setf people '())
(push (Person "John Doe") people)
(push (Worker "Jane Doe" 3000) people)

(define (describe person)
  (string (:name person) " earns " (:salary person) " dollars."))

(map describe people)
#19
newLISP newS / Re: newlisp.vim 1.37
June 02, 2013, 03:14:50 PM
Wonderful. Thanks, Cyril.
#20
newlisp has optional arguments (no need to point them out with a special keyword).

As I understand it, newlisp doesn't explicitly support keyword arguments although you could achieve a similar effect using association lists or hashes.
#21
Whither newLISP? / Re: Howto Solve Context Collision
March 23, 2013, 07:53:16 PM
Excellent, Lutz.



Those WP articles and the PDF helped a lot. Thanks! :-)



Your example of handling separate concerns with contexts was clear. That reminds me of one of the GOF patterns... strategy? (I never got into the habit of quoting GOF patterns.)



However, your example shows... completely separate concerns rather than cross-cutting concerns. I googled for AOP in newlisp rather unsuccessfully. It seems that dragonfly has a (wrap_func) that provides an aspect of it (no pun intended).



I will have to play with this to truly understand it. But now I have the means to begin that journey. Thanks, Lutz & rickyboy. Much appreciated. :-D
#22
Whither newLISP? / Re: Howto Solve Context Collision
March 22, 2013, 11:08:35 PM
Thanks, rickyboy! That helped a lot. I installed racket to see the difference.



Hmm... This is premature of me to say so, but... I like the way newlisp does this better than racket. Which is to say... to my mind, that your are letting x have another value before (g) is called, then it better show up in (g) with that value - not the lexically scoped value, 42.



I think I know why this is strange to me now. I am used to lexically scoped languages where any modification to x would be a permanent change, so referencing x back at the main scope after the (f 2) call would yield the now-modified value, 13 (in the languages I use). So, the (let ((x 13)) ...) code temporarily shadows (you say binds) the global (you say free (the free term may not be limited to globals... right?)) variable x with the value 13. When that (let) expression ends, the binding ends and therefore x goes back to being the value it was prior to this dynamic scope change, 42.



Ok. Apart from some obvious quirks in my terminology, let's say I get that now. Thank you! So, now I'd like to understand what Lutz meant when he said there were good uses for dynamic scope that us lexical scopers are deprived of. Could you elaborate on: "switching and separation of concerns"?



:-D
#23
Whither newLISP? / Re: Howto Solve Context Collision
March 20, 2013, 09:46:50 PM
QuoteToday, I believe that the problems with dynamic scoping are vastly exaggerated, which is sad, because people have stopped using dynamic scoping as a tool, exploiting its special characteristics, e.g.: switching and separation of concerns.


Lutz... I would love to hear more about this. I am a struggling convert to the world of functional programming and dynamic scope bewilders me. :-/
#24
newLISP newS / Re: newLISP Development release 10.4.6
February 05, 2013, 10:20:34 PM
Hmm... Fair enough.



I see them as serving different purposes though. JSON is fine for machine-machine interfacing, but not well suited to human editing. YAML is much friendlier in that department.
#25
newLISP newS / Re: newLISP Development release 10.4.6
February 05, 2013, 03:51:50 PM
Very nice. Any plans for doing the same for yaml?
#26
newLISP in the real world / Re: external filter
January 30, 2013, 07:09:03 PM
Thanks, Lutz. I'll play with those variations.
#27
newLISP in the real world / external filter
January 29, 2013, 08:19:25 PM
What is a more idiomatic way to do this? :


(set 'tmp-file (open "/tmp/file" "write"))
(write tmp-file (join (map markup (parse pretext "n" 0)) "n"))
(close tmp-file)
(setf posttext (join (exec "fmt -68 /tmp/file") "n"))


It feels dirty to use a /tmp/file like that. Ideally I'd like to pipe a string through `/bin/fmt` capturing its STDOUT, all within newlisp.
#28
An only slightly more harmonious solution might be to go the other way and expect URL literal command-line arguments to be marked up so as to prevent them being remotely executed by newLISP. Prepending a + is one simple way:


newlisp +http://www.google.com/bank.html

getting the url then as:


(setf url (1 ((main-args) -1)))

This is only slightly better in that it doesn't assume the protocol is always http.
#29
newLISP in the real world / Re: crypto module on ubuntu
January 24, 2013, 06:38:39 AM
cool
#30
newLISP in the real world / Re: crypto module on ubuntu
January 24, 2013, 01:18:23 AM
just a stab in the dark here, csfreebird, but you said you were on amd64 but then went and installed:


apt-get install libssl0.9.8:i386

?



I am assuming the error message:


wrong ELF class: ELFCLASS32

is saying that it expected a 64-bit ELF class...