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

#106
Hi...



I cannot get the following example to work:



(set 'data (1 1 2 2 2 2 2 2 2 3 2 4 4 4 4) )

(unique data)

(println data)



I keep on getting the subject error -- yet the example is out of  "Introduction to newLISP" - except for the (println .. ) line.

What am I missing? TIA...
#107
Anything else we might add? /
August 15, 2007, 10:57:06 PM
Quote from: "Jeff"Because "i was 5" is the value of the catch.  It was not caught into any symbol, so there was no output.  If you run it inside the repl, the entire expression will evaluate to "i was 5", but only the print statement will print things out.



Here is a more comprehensive tutorial I wrote on newLisp error handling and flow control using catch/throw:



http://artfulcode.nfshost.com/files/simple-error-handling-in-newlisp.html">//http://artfulcode.nfshost.com/files/simple-error-handling-in-newlisp.html


Thanks for the URL. Nice article!! Helped a lot.
#108
Hey...



on p19 of "Introduction-to-newLISP" the following example is given:



(catch

  (for (i 0 9)

    (if (= i 5) (throw (string "i was " i)) )

    (print i " ")

  )

)



For some reason, the above does not print "i was 5", yet it does print the correct output. What am I missing? TIA...

--

dukester
#109
Anything else we might add? /
July 27, 2007, 06:56:13 AM
Quote from: "Jeff"When visually parsing a lisp list, evaluate from the inside out.  After learning to do this, lisp's syntax will become so much easier to visualize than imperative programming, because with lisp you are, basically, writing the actual internal structure of the program, rather than a more declarative syntax that would get parsed and turned into something resembling the lisp structure.



When writing a lisp program, write from the bottom-up.  It's all about abstraction.  First, you write the most primitive elements your program will need.  Then, you write other functions that will use those functions in order to abstract the more low-level stuff.  In the end, you write a much smaller set of functions/macros that will be the api to the program.  These have convenient syntax and build on the lower level elements of the program.


Sounds a bit like Forth methodology: design top-down; develop bottom-up. I never gave Forth a fair chance though. However, I'm finding newlisp more intuitive and way simpler to learn. Thanks!
#110
Anything else we might add? /
July 27, 2007, 06:53:07 AM
Quote from: "cormullion"
Quote from: "dukester"Let's see if I'm getting this:



(upper-case (println "hello world"))



is a list of 2 functions and some data... correct?



1st-- println  function does its thing and displays the data

2nd-- upper-case function does _its_ thing on the data

3rd-- REPL displays the last item in the list



Am I close?

Yes! :-)



To put it another way, (upper-case (println "hello world")) is a list in which the argument to the 'upper-case' function is another list which contains a function call and an argument (or data as you call it).



1 - A println function call in a list returns a value. As a useful and pleasant side effect , it displays some string data somewhere and adds a newline to it too as it does so.



2 - upper-case now has a chance to do its 'thing' with the string that it's handed by the inner list. It doesn't 'know' where the string has come from, or what it originally looked like before it was procesed, and knows nothing of standard output or displays either. It sees a string - that's good enough, and all it needs to know.



3 - The result of the evaluation of the 'upper-case' function is displayed by the newLISP interpreter. This isn't the original data, but the value of the 'upper-case' function call, which in turn depended on the value of the 'println' function call.



So - can you predict how the following is evaluated?


(upper-case (reverse (lower-case "ABC")))

Look at the innermost list first.



hope this helps!


You bet it helps!



I'm familiar with nested function calls from Perl, PHP and Euphoria. The above code is an excellent newlisp example IMHO.



I was getting hung up on the REPL behavior of diaplaying the last element of a list when I was using "println" from the newlisp console. Thanks again!
#111
Anything else we might add? /
July 26, 2007, 06:57:29 PM
Quote from: "Jeff"That's exactly right.  Anything printed will have the additional side effect of printing the value of the expression entered.  READ-EVAL-PRINT-LOOP means that the expression is read, evaluated, the value is printed, and then then started over.  Printing a statement returns the text printed, so (println "Hello world") both prints "Hello world" and then evaluates to "Hello world", so the repl will print out the value in the course of evaluating the expression, and then display the result of that expression.  If you were to type (upper-case (println "hello world")), it would first print "hello world", then print the value of the entire expression, "HELLO WORLD".


Let's see if I'm getting this:



(upper-case (println "hello world"))



is a list of 2 functions and some data... correct?



1st-- println  function does its thing and displays the data

2nd-- upper-case function does _its_ thing on the data

3rd-- REPL displays the last item in the list



Am I close?
#112
Anything else we might add? / REPL behavior
July 25, 2007, 06:09:58 PM
i'm new to newlisp! Currently reading "newlisp in 21 minutes" as an intro.



(println "Hello World!")



prints twice at the newlisp console because:



REPL prints it  once

println prints it a second time



Is this a correct interpretation of whats going on? TIA...

--

dukester
#113
newLISP in the real world /
May 10, 2007, 06:33:33 AM
Quote from: "cormullion"late but....



I usually edit in an editor (TextWrangler at present) and hit the 'run' command. It works fine. Recently, trying to track


So this 'run' command must be equivalent to other editors' tools option which allow you to set up a compiler/interpreter to execute the code?


Quote from: "cormullion"
down some error of mine, I've started running functions in the terminal. So:



[ I'm editing then I save ...]

[ Command-Tab to terminal running newlisp]

> (load "file.lsp")

> (debug (function-exp))



and then I'm in the debugger, stepping through the function. Although the debugger is simple, I like that simplicity.




Yep! that's what I've done in other languages in the past.




QuoteI've put


(trace-highlight "27[0;32m" "27[0;0m")

into my init.lsp file, because I can never remember the codes. Now, when tracing a function, the current expression is in green... I'm starting to appreciate the way you can type in any expression at any point in the executing code.




Cool. Ill have to try this.
#114
newLISP in the real world /
May 08, 2007, 08:31:41 PM
Quote from: "Lutz"At the end of this page:



http://www.turtle.dds.nl/newlisp/index.html">http://www.turtle.dds.nl/newlisp/index.html



you find a nice screenshot of running a shell inside a split window in Vim.



Lutz


I use Vim a lot when I'm on my FreeBSD box. So you edit the source code with Vim. You run the code from another xterm window? Or from within Vim itself? Never done the latter - how do you get _that_ to happen?
#115
Hey all.....



I'm new to newLISP! I'm wondering if there's an ideal way to program in newLISP? With some other languages that I've used, I typically have to windows open:

1. vim editor

2. compiler



I edit my source code in one window; ALT TAB to the next window; UP ARROW for the latest CLI command (i.e. newLISP whatever.lsp); program output; ALT TAB to editor.



Is that what you guys do? I realize that some editors have the capability of piping the the current file  to a pre-defined compiler. Sometimes setting these up can be a PITA ;)



Anyway, TIA for any pointers/suggestions/comments.L8r...