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

#1
Anything else we might add? /
November 07, 2005, 05:05:15 PM
Thanks Lutz.  I really needed to read the section on the eval function a little more carefully.
#2
-

When using a function to generate symbols for the creation of contexts the following behavior can be observed:



> (define (build-sym x) (sym (string 'C x)))
(lambda (x) (sym (string 'C x)))

> (context (build-sym 2))
C2
C2> (context MAIN)
MAIN

> (context? (build-sym 2))
nil
 
> (context? (eval (build-sym 2)))
true

> (context (build-sym 2))
C2
C2>



I find this a little odd since context symbols evaluate to themselves and (build-sym 2) seems to be evaluating to a context the second time it is invoked.  But I think the following is really confusing:



C2> (context MAIN)
MAIN

> (setq ctx (build-sym 2))
C2
> (symbol? ctx)
true
> (context? ctx)
nil

> (setq cty C2)
C2
> (symbol? cty)
nil
> (context? cty)
true

>ctx
C2

>(symbols)
... ? @ C2 MAIN NaN? ...


 So will the real C2 please stand up...?  There is only one C2 in the symbol table but there is clearly a different C2 in 'ctx than there is in 'cty.  Except:



> (set ctx "something else")

symbol is protected in function set : C2

> (context ctx)
C2
C2>


It is obviously evaluating to a context here.  Should not (context? ctx) return true?  Or if it is really hiding the function (build-sym) underneath its "symbol" C2 then should not (lambda? ctx) return true?  The documentaion is not clear about out how these phantom symbols for contexts (sometimes) need another level of evaluation.

-
#3
Anything else we might add? /
November 05, 2005, 01:15:32 AM
I'm a println man myself from way back but I used the debugger today.  I was about eight levels deep in a sea of parentheses, they were balanced (though not very well as it turned out), and I couldn't figure why I was getting different runtime errors as I switched things around, until I started watching the little pound signs lining up during the trace as I stepped through the evaluations.



Which reminds me to ask:  It would be nice to have readline support *inside* the debugger.
#4
Anything else we might add? / Re: Fed up with Lambda ?
November 04, 2005, 02:10:46 PM
Quote from: "newdep"The unlambda language:



http://www.madore.org/~david/programs/unlambda/">http://www.madore.org/~david/programs/unlambda/


LOL.  "First-class continuations" - I love it!

-
#5
newLISP in the real world /
November 04, 2005, 01:56:02 PM
Quote from: "newdep"
Is 'max quicker on a sorted or unsorted list ;-)


Ha ha, very funny!  One thing for sure, sort is a really slow way to get the max:



> (time (sort c))
183

> (last c)
3549



FWIW, I can't really see much difference in max with sorted input:



> (time ((push max c) (eval c)))
27


-
#6
newLISP in the real world /
November 04, 2005, 11:10:14 AM
Quote from: "HPW"
...shorter.


But not neccesarily faster:



> (setq c (flat (dup b 1000)))
....35 51 34

> (time (apply max c))
49

> (time ((push max c) (eval c)))
23

> (pop c)
max <C42C>

> (time (apply max c))
48



I'm wondering if pushing a function onto a list is always faster than mapping apply or is it just a peculiarity of the max function with a large list?

-
#7
Anything else we might add? / Re: unattended symbol
October 30, 2005, 02:34:22 PM
Quote from: "Dmi"
Note about the last NCR:x symbol. Where is it from?

I think it must not be present... Or I have a mistake somewhere?


The NCR:x is the symbol x in the dolist and was created along with NCR:ctx and NCR:import-ncurses when the function "import-ncurses" was *defined*.  



The various strings were used to create symbols like NCR:COLS etc... during the *execution* of "import-ncurses".

-
#8
newLISP in the real world /
October 27, 2005, 01:04:57 PM
Quote from: "pjot"


I also thought to 'do something with sym', and I see your solution points in this direction. But you're using the 'cons' statement, which I never used myself before;


Peter,



I think I might have left out a few functions in that last example.  However here is some working code I wrote yesterday that shows how to construct a context name from an array of ints and an array of capital letters.  It is instantiaing a context for a point in 3-dimensional space.  But you could use some functions like it to create an association list of int-address lists too...

(don't use flat as that un-conses the pairs!)




(define (merge lst1 lst2) (map cons lst1 lst2))

(setq XYZ '(X Y Z))

(setq xyz '(156 209 3))

(context (sym (join (map string (flat (merge XYZ xyz))))))
X156Y209Z3
X156Y209Z3>



-Jim

-
#9
Anything else we might add? /
October 27, 2005, 11:41:29 AM
Quote from: "Fanda"Honestly... Concept of this game isn't mine. I played one that has 5x5 field. I couldn't solve it (only by accident), so I decided to make my own version where I can better see the field and can think about it more :-)



Later on, I added more levels ;-)



Fanda


Good for you!  I can't solve the 5x5 even by accident.  I'm sure there is some sort of standard strategy for it but every time I get down to 2 squares I get stuck....  :-(



I guess I'll have to console myself by appropriating some of your Tcl/Tk code tricks for my current project!

-
#10
newLISP in the real world /
October 27, 2005, 11:33:03 AM
Quote from: "pjot"
So every time when I print the address of an array member, the address changes....?!?!



Peter


The manual defines "address" to work only with "int", "double flost", and "string".  There is some more documentation of memory management in the FAQ at:



http://newlisp.org/MemoryManagement.html">//http://newlisp.org/MemoryManagement.html



How about using an association list for the array that you set each time you assign a value to an int:

 

(setq indx 0)
(inc indx)
(push (cons ((sym (append (string (i (indx))))) (sym (adress (sym (append (string (i (indx))))))) alst -1)

"alst" would then be: ((i1 address) (i2 address) ... )


or some such.  Also, perhaps you could store the ints as chars in a string and index into that off of the string address.

-
#11
I am trying to write a function that creates a number of contexts of the same type all with the same default function, a sort of class constructor method, if you will.  It seems possible but I can't get it to work (at least without a macro).  

> (define (myProc) (println "hi"))
(lambda () (println "hi"))

> (def-new 'myProc 'myCtx:myCtx)
myCtx:myCtx

> (myCtx:myCtx)
hi
"hi"

> (context? myCtx)
true

> myCtx:myCtx
(lambda () (println "hi"))

Great!  So let's do it from a variable:

> (set 'myVar 'myCtx2:myCtx2)
myCtx2:myCtx2
 
> (def-new 'myProc myVar)
myCtx2:myCtx2
 
> (context myCtx2)
myCtx2

myCtx2> (myCtx2)
hi
"hi"

So far so good, let's set the variable programatically:

> (set 'myVar (sym (append "myCtx" (string 3) ":myCtx" (string 3))))
myCtx3:myCtx3
 
> (def-new 'myProc myVar)
myCtx3:myCtx3
 
> (context? myCtx3)
nil

> myCtx3:myCtx3

context expected : myCtx3

How do I set myVar so that "def-new" evaluates it in the same way as when I set it to 'myCtx2:myCtx2 explicitly?



Do I indeed need a macro for this or is it something I'm just not getting about symbols and newLISP's evaluation of variables?

-
#12
Anything else we might add? /
October 23, 2005, 11:02:53 AM
Quote from: "Lutz"Regarding an implicit 'if': I have been going back and forth on this in my mind, I am just not sure if I want it, if it leads to too much ambiguities from a users point of view? When the first expression evaluates to 'nil' things are clear, but what if the the xpression evauates to a list or number? Is it now impicit indexing or impixit 'if' etc.


Indeed, with an implicit "if" it will take longer to comprehend what's going on when reading unfamiliar source code; perhaps even one's own after a lapse of a few months.  ;-) The implicit "else" in "if" constructs is already quite enough, thank you very much.



OTH, addition of this feature would help greatly in facilitating the holding of an annual "most obscure code" contest for newLISP, such as they do for C and PERL.

-
#13
Quote from: "statik"Taken from a debate in the #newlisp channel on freenode, here was this guy's complaints/arguments:



<someguy> well, newlisp's memory manager really sucks

<someguy> because it doesn't handle shared structure


Put them in a context.


Quote
<someguy> it copies objects when you pass parameters

<someguy> because its inefficient

<someguy> also it means you can't have first-class arrays or hash tables


Put them in a context.


Quote
<someguy> you have to name all arrays and hashes by symbols, and pass symbols, you can't just pass an anonymous hash

<someguy> it severely limits the language


Not really.  The "S" in LISP stands for "Symbolic".  LISP is all about symbols.


Quote
<someguy> performance?

<someguy> sbcl is much faster

<someguy> except the design of newlisp is quite poor

<someguy> and i noticed the flawed memory management,


A memory management system not to his taste perhaps.  NewLISP imemory management is certainly well described though.


Quote
 and lack of first-class arrays and hashes


Redundant as well as incorrect.  Again, use contexts if you must.


Quote
<someguy> more problems in newlisp than high-quality common lisps like sbcl

<someguy> in fact, i don't see anything newlisp is good for


Try: http://newlisp.org/index.cgi?page=Applications">http://newlisp.org/index.cgi?page=Applications


Quote
<someguy> i've also looked at the implementation code, its a mess

<someguy> in that sbcl is better in every way

<someguy> it has first class arrays, hashes, real gc, a better object system

<someguy> newlisp is a strict subset of common lisp, except the really broken parts (copying all values when passing parameters, 'contexts')


No, contexts are passed by reference.


Quote
<someguy> also there's no number tower

<someguy> so integer math overflows

<someguy> that's really bad

<someguy> you can have a file larger than 2gb, but newlisp cannot represent its size

<someguy> algorithms like md5 and sha1 hashing, and rsa crypto all use bignums


You've got me there.  Aren't there bignum C libraries available?  Can NewLISP not interface to them?


Quote
I could argue all day with this guy


I think you should.
#14
Quote from: "pjot"Hi newLispers,



With the GTK-server it is possible to create a drawing on a canvas. I made a demonstration here: ...




It is always a pleasure to read your well formatted code!  However, I much prefer the formatting scheme for parentheses that you used in "fractals.lsp" to the one you employed in "canvas.lsp".  

 :-)
#15
Quote from: "pjot"Hi newLispers,



With the GTK-server it is possible to create a drawing on a canvas. I made a demonstration here: ...




It is always a pleasure to read your well formatted code!  However, I much prefer the formatting scheme for parentheses that you used in "fractals.lsp" to the one you employed in "canvas.lsp".  

 :-)