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

#601
newLISP newS /
October 04, 2007, 01:08:41 PM
Quote from: "cormullion"
Quote from: "TedWalther" The fun of a Commodore 64, the power of Unix, the readability of Python.


I don't know quite what that means, but perhaps it ought to go into http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1128">//http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1128 one day!


The Commodore 64 had sound and graphics, a floppy drive, and it worked with your TV set.  It was FUN.  It's built in BASIC interpreter let you peek and poke into the innards of the machine right from the beginning.  It hid nothing from you.



We all know Unix is powerful.  The first multi-tasking, multi-user, network enabled OS that ran on an inexpensive PC.



Python.  Python lends itself to writing readable code.  So does newLISP.  In what other language can someone hand me a one line "indent" function? WOW!



Ted
#602
newLISP newS /
October 03, 2007, 09:40:46 PM
Quote from: "rickyboy"Hi Ted!  This(replace "([^rn]+)([rn]+)" foo (string "tt" $1 $2) 4)
will meet all your requirements (if I read them correctly), including not putting tabs on blank lines.  Cheers, --Rick


Rick, thank you!  Just what I was wanting.



Cormullion, thank you for your solution as well.



Boy, newlisp is just the greatest new language I've come across in years.  It brings back all the fun I used to have with Commodore BASIC.  The fun of a Commodore 64, the power of Unix, the readability of Python.



Ted
#603
(setq foo "anbncn")

(indent foo "tt") => "ttanttbnttcn"



Hi guys.  I've been fiddling with "replace" and using regex functionality, but not sure how to make it do what I want above.



I want the start of every line to have some indent characters inserted, but if it ends with a newline, I don't want indent characters inserted after the last newline.  And there isn't a newline at the beginning of the string, but I want the indent characters there.  This is as close as I made it:



(replace "(^|n)" foo "\ntt" 0) => "\ntta\nttb\nttc\ntt"



Can someone show me what is the right way to define the "indent" function?  And if it was robust for various values of newline, such as nr, rn, and r, that would be great too. Empty lines don't need any indent characters added, which may make it easier.



Also, would it make sense for this (indent) function to be part of the base install?  Also, I am doing (constant 'cat append) to save typing when I want to join a bunch of strings; could that be made standard in subsequent release of newlisp as well?



Ted
#604
Anything else we might add? /
September 04, 2007, 07:51:08 PM
Quote from: "cormullion"That's one way. Or perhaps you could investiage a simpler way:


(define (string! s)
    (replace {((.*?))} s (string (eval-string $1)) 0))

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

(string! {a  +  b +
c = (+ a b c)})

;->
a  +  b +
c = 6


and you're keeping your white space.



I don't think you can get parentheses into symbol names, though, unless you enclose them with brackets.


Thanks, I think we're getting closer.  What if the parens are nested?



(string! {a b c = (+ a (* b c))})



The eval function will work correctly, but will that regex match up the proper parens?  Is there a regex somewhere that matches matching parens even if there are interior paren sets?



Ted
#605
Anything else we might add? /
September 04, 2007, 10:53:18 AM
For the (string ...) function, I'd like the reader to evaluate the first argument in the list before proceeding.  Then if it is a special, like string, it would "read" the rest of the string appropriately.  So, for string, when the reader sees "(string " then it would kick into a mode where everything up to the next ) is shoved into a string.  Except that a ( inside the string would kick it back into regular mode.



Ted
#606
Anything else we might add? /
September 04, 2007, 09:25:09 AM
Thanks Cormullion.  Your code looks close to what I want.



Two issues:



1) I'd like to preserve whitespace between elements of the string, especially carriage returns.



2) Even if whitespace can't be preserved, I'd like to have "symbols" that contain any character at all except for the "(" character, unless it is backslash escaped, like "(".



I guess this involves some modifications to the reader function.  Is that possible in newlisp?



Ted
#607
Anything else we might add? /
September 03, 2007, 10:53:17 PM
Thanks Lutz.  I may just have to intersperse {} strings with newlisp code.  Not quite the minilanguage I wanted, but close enough to be an improvement over what I have right now.



What would it take to make a top-level function (string ...) that was a "special" function the way (lambda) is a special function?  Or (list) ?  Just as (list ...) returns its elements as a list, (string ...) would return everything up to the closing paren as a string?  So, (string foo bar baz) would return the string "foo bar baz".



I think with a function like that, I could do everything I want in the way of a minilanguage.



Although, inside the (string ...) function, parenthesis would have to be backslash escaped, so that newlisp code could be embedded, as in this example:



(string a + b + c = (+ a b c))

=> "a + b + c = 3"



Ted
#608
Hi.  I want to do something special with NewLISP.  I've been told that it is bad procedure, or almost impossible to do in other versions of LISP.



I want to integrate the Lilypond minilanguage into Newlisp.



I want to have a special function (lilypond ) and everything inside the brackets is interpreted differently.  The definition of "symbol" changes, etc.   I want newlisp to interpret it like this:



Take this:



(lilypond-notes

sacredHarpHeads set autoBeaming = ##f

        g2. d'2 d4 | d (c) b a2 g4 | a2. b | g2 g4 b2 a4 | b (c) d e2. | g d2 e4 | d (c) b a2. |b g2 g4 | d' (b) a b2.~ | b

)



And I want newlisp to treat it like this:



[text]

sacredHarpHeads set autoBeaming = ##f

        g2. d'2 d4 | d c b a2 g4 | a2. b | g2 g4 b2 a4 | b c d e2. | g d2 e4 | d (c) b a2. |b g2 g4 | d' (b) a b2.~ | b

[/text]



However, there is a difference.  I also want this to work:



(lilypond-notes g2. d'2 d4 | d c b (slur a b c))



should output



[text]g2. d'2 d4 | d c b (a b c)[/text]



That is, I want "slur" to be a macro that expands to something like (print (append "(" (lilypond-notes a b c) ")"))



And I want to be able to incorporate other lisp things in too.



So (lilypond-notes a b (tempo 60)) should output "a b tempo 60 4"  So the (tempo) function is just normal lisp, and symbols etc are interpreted as normal.



So I want to be able to have custom functions that interpret symbols differently, and still interleave and mingle functions of newlisp code.



Final example of what I want to do:



(define (tempo bpm) (push bpm *bpm*) (print "tempo " bpm "4"))



(lilypond-notes a'4 b2. (fermata c) d) should output this:



"a'4 b2." (tempo (/ (pop *bpm*) 2)) "fermata c" (tempo (* (pop *bpm*) 2)) "d"



and this would result in:



[text]

a'4 b2. tempo 40 4 fermata c tempo 80 4 d

[/text]



Any ideas how to do this?  This minilanguage would save a lot of typing, and associated typos, in the music typesetting work I do.



Ted