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

#1
Anything else we might add? / Re:
September 03, 2022, 03:31:46 PM
Sorry to bring up to life such an older post but I think it's interesting to discuss it a bit further


Quote from: Jeff post_id=13069 time=1212583186 user_id=354


Previously, if I wanted to write in an object-oriented style:


(context 'Point)
(setq x 0 y 0) ; default slot values

(define (print-point)
  (println (format "(%d, %d)" x y)))

(context MAIN)
(new Point 'my-point)
(setq my-point:x 4 my-point:y 12)
(my-point:print-point) ; => prints "(4, 12)"


Now, if something changed in the context Point, it would not change in my-point.  This is prototype-based OO, just as in Javascript.


No, an 'object' defined in such a way is not a prototype-based OO at all.  That my-point 'object' has not a refererence to its class neither its prototype, not only it is not a prototyped object but it is not even an object,  by definition an object knows the class it belongs to and this object doesn't know so it's not an object,  in prototype-based OO there's no class, everyting is an object and you create a new object from another object as prototype, so the new created object has a reference to its prototype, the object used as model for creation,  this my-point 'object' has no reference to its prototype so it is not a protoype-based object.  The only reason to call it an object is by the fact it's a data structure that holds data and behaviour.



By contrast, a FOOP object is a real object since it has a reference to its class and encapsulates data and behaviour.


Quote from: Jeff post_id=13069 time=1212583186 user_id=354
Therefore, if I wanted to implement a counter using a closure, I could do so like this:


(context 'Counter)

(define (Counter:Counter ctx (start-from 0))
  (new (context) ctx)
  (setq ctx (eval ctx))
  (setq ctx:current start-from))

(define (increment (n 1)) (inc 'current n))

(define (decrement (n 1)) (dec 'current n))

(context MAIN)

(Counter 'counter 100)
(counter:increment 10)
(counter:increment 12)
(println counter:current) ; => 122



with this code you are using a context to represent an object, that's ok, the problem is you are pretending the object is also an instance of a class, and that's not the case, you are using context to represent both classes and objects, an pretending Counter is a (class) constructor for instance objects of that class, which is not. With


(Counter 'counter 100)

you're pretending to create a new instance counter of class Counter ,  both (class and instance) represented as contexts.  

Pretending this means instance counter knows about its class, Counter, but this is not the case because context counter is a copy of context Counter (thus including all its symbols, same data and functions) but have no reference to Counter context and no idea about a Counter (i.e. a symbol with its class name).



In other ways, let's suppose we have a function returning the class name:


(define (classname) (context))

this function works for the class:  (Counter:classname)  => Counter  but not for the instance  (counter:classname) => counter  when it should return Counter as well, and there's no way to write a function in the instance (context counter) that returns its classname because it has no way to know what class it was copied from


Quote from: Jeff post_id=13069 time=1212583186 user_id=354
I'm not confusing classes and instances :).


yes I think you are ;-)





Anyway as you sure know, if you want to get a closure you don't need all that structure, simply use the context as is:



(context 'Counter)

(define (start  (n 0))  (set 'current n))
(define (increment (n 1)) (inc current n))
(define (decrement (n 1)) (dec current n))

(context MAIN)
(Counter:start 100)
(Counter:increment 10)
(Counter:increment 12)
(println Counter:current) ; => 122
#2
Anything else we might add? / Re: forum problems?
January 06, 2022, 01:37:47 PM
Quote from: newdep post_id=25081 time=1640386029 user_id=38
pasting code ..works again... ;-)


Hallelujah!   ;-)



Is it known the reason of failure?
#3
Anything else we might add? / Re: forum problems?
December 19, 2021, 02:59:20 PM
it seems it is not allowed to type the sentence:
Quoten having a

with n and a quoted with double quotes ("n" and "a")



it also seems it is not allowed to type and eval application in a code block, not (eval) nor "eval" and even it seems you cannot type any word in parens like (x) in a code block



very strange and weird



I've checked with several browser so I'm pretty sure it's not a matter of web browser used.
#4
Quote from: cameyo post_id=25005 time=1617113250 user_id=732
Function to create a function with name and parameters:
(define (make-add name val)
  (let (f nil)
    (setq f (string "(define (" name " x) (+ " val " x))"))
    (setq name (eval-string f))
  name))

Creating a function
(make-add "sum-10" 10)
out: (lambda (x) (+ 10 x))

Using the created function
(sum-10 3)
out: 13

Do you know of another way (instead of using strings) to create a function with another function?


your example of a made-add function to create a sum-10 function:



(define (make-add n v)
  (evaluate (list 'define (list n 'x) (list '+ v 'x))))


and using it:



(make-add 'sum-10 10)
out: (lambda (x) (+ 10 x))
(sum-10 3)
out: 13


a more general way to create any funcion with name n having parameters a and a body b with minor checking of parameters and function name:



(define (mkf n a b)
    (evaluate (and (symbol? n) (list 'define (if (apply and (map symbol? (cons n a))) (cons n a) n) b))))


and using it:



(mkf 'sum-x-y '(x y) '(+ x y))
out: (lambda (x y) (+ x y))
sum-x-y
out: (lambda (x y) (+ x y))
(sum-x-y 4 5)
out: 9


the function expects name and parameters to be symbols and defaults to a symbol definition if you pass bad parameters, that is paremeters which are not symbols, in this case is defines a symbol with the name passed and the evaluated body as value (or nil if evaluation fails). If the name of the function to be defined is not a symbols it returns nil and doesn't define anything:



x
out: nil
y
out: nil
(mkf 'sum-x-y-with-bad-parameters '(x y 3) '(+ x y))
out: ERR
sum-x-y-with-bad-parameters
out: nil
(define x 3)
out: 3
(define y 34)
out: 34
(mkf 'sum-x-y-with-bad-parameters '(x y 3) '(+ x y))
out: 37
sum-x-y-with-bad-parameters
out: 37
(mkf 4 '(x y 3) '(+ x y))
out: nil
(mkf nil '(x y) '(+ x y))
out: nil


Take this as an example about how to face the question, of course it needs more checking to be robust and correct (variable capture...).



Note: in this post "evaluate" means "eval", because phpBB does not allow me to type it even in code section, so assume this code as the very begining:


(define evaluate eval)
#5
Anything else we might add? / forum problems?
December 19, 2021, 01:46:20 PM
is there any problem with the forum?



every time I try to reply including quote and code I get an internal Server Error
#6
newLISP newS / Re: Happy Birthday newLisp
December 19, 2021, 01:29:06 PM
it seems too old for that a young ! ;-)
#7
newLISP and the O.S. / Re: Not start on Win10
December 14, 2021, 01:11:44 PM
Quote from: First_Spectr post_id=24181 time=1512165777 user_id=1252
I found a solution, in my system used java from "jre-9.0.1" folder, I rewrote the command like C:Program FilesJavajre1.8.0_151binjava.exe" -jar .guiserver.jar 64001 newlisp-edit.lsp and now all work perfect. Unfortunately shortcut still not work: guiserver.jar 64001 newlisp-edit.lsp
Error: Could not find or load main class D:Program Files (x86)newlispguiserver.jar
If somebody know how to fix it - let me know please. The basic problem can be considered solved, thank you very much.


if your problem is to execute jre 1.8.0  rather jre 9.0.1 when executing directly a jar file  you should check the file & program association, in a cmd window type:



C:>assoc .jar
.jar=jarfile

C:>ftype | find "jarfile"
jarfile="C:Program Files (x86)Javajre1.8.0_261binjavaw.exe" -jar "%1" %*


you should get the program is associated to jar files in your windows, in my case it is "C:Program Files (x86)Javajre1.8.0_261binjavaw.exe"



if you want to set another one (jre 9.0.1 or in your case jre 1.8.0) simply type:



C:>ftype jarfile="C:Program Files (x86)Javajre1.8.0_261binjavaw.exe" -jar "%1" %*


supposing your jre 1.8.0 is in path C:Program Files (x86)Javajre1.8.0_261, if not replace as convenient



After doing this you can simply type the name of the jar and it will be run with the right java program like in:


guiserver.jar 64001 newlisp-edit.lsp
#8
newLISP and the O.S. / Re: Not start on Win10
December 14, 2021, 01:01:24 PM
Quote from: First_Spectr post_id=24180 time=1512135864 user_id=1252
Interface looks Снимок2.PNG


I think this is more related to wrong paths when executing newlisp-edit.lsp,  check the path variables.
#9
newLISP and the O.S. / Re: Not start on Win10
December 14, 2021, 12:50:06 PM
I see this thread is a bit older but I would write something related in case being of any help for anybody



I had problems executing guiserver a few days ago, the problem is displayed a  "ERR: cannot find working directory" in the console text-area and guiserver was not able to execute newlisp interpreter so you cannot execute anything.



After investigating under the sources for a while I resolved the issue  hard coding the path in  file newlisp-edit.lsp  in order it search in several places (the hardcode one, the HOME env var , etc)



Another problem I had is newlisp is installed by default in Program Files (x86) and that is a read only folder in windows 10, so is complicated to make changes (you can if editing files as administrator or running a cmd as administrator) but for easy going I ended up copying the whole newlisp folder in a writable path,.  



After doing that sometimes I ran the jar in Program Files while using my writable folder as working dir and doing so I got a lot of alert windows saying it cannot find buttons or other objects, maybe your problem could be related to this, try to run everything in the same folder and check if its readable and maybe also writable.  Hope it helps.



It would be great to use a config file for this stuff (similar to settings but a real file) and also it would be great to reverse the control, it would be great to control java from newlisp repl rather to control newlisp repl from java
#10
newLISP and the O.S. / Re: Not start on Win10
December 14, 2021, 12:38:02 PM
Quote from: First_Spectr post_id=24179 time=1512121754 user_id=1252
I removed /local/newLISPsplash.png and now I have many errors like "Could not create image-button", but lisp up and running, thanks for that. Where can I find newLISPsplash.png?


/local is a valid path, it refers to jar itself, that is files in /local are files stored internally in the guiserver.jar file,  for this reason you can refer to newLISPsplash.png since it's an image stored in the jar file, but you can also provide another image using a diferent path such as /tmp/myScreen.png
#11
Quote from: HPW post_id=24974 time=1607372710 user_id=4
I have no problem with the paranthesis and they belong to every lisp.

For me a good editor solves the problem with paranthesis checker.


I agree but this proposal is a funny one and may be interesting as an option in IDE preferences for pretty printing


Quote from: HPW post_id=24974 time=1607372710 user_id=4
(define (initial-clauses str)
  (set 'start (array rows columns (map int (explode str))))
  (for (row 0 (sub1 rows))
    (for (col 0 (sub1 columns))
      (when (> (start row col) 0)
        (push (string (to-var row col (sub1 (start row col))) " 0")
               problem
        )
      )
    )
  )
)

With the proper indention you see which paranthesis belog to the opening paranthesis.


that indentation is far away from proper indentation,  historically well stablished proper indentation for that code is:

(define (initial-clauses str)
   (set 'start (array rows columns (map int (explode str))))
   (for (row 0 (sub1 rows))
     (for (col 0 (sub1 columns))
       (when (> (start row col) 0)
         (push  (string (to-var row col (sub1 (start row col))) " 0")  problem )))))


with minor variatons as a matter of style
#12
pretty interesting but just for pretty printing newlisp code, it's not a notation for code input because is harder than real one and also clumsy since you have to keep the count of opened parens in your head to write the right upper number.



more interesting would be an editor automatically doing the pretty printing or even better the newlisp REPL with some kind of activation
#13
newLISP in the real world / newlisp 10 changes
November 16, 2020, 02:28:03 AM
Hello, I've read in several places, i.e. https://github.com/kanendosei/artful-newlisp">https://github.com/kanendosei/artful-newlisp , there're code that needs to be rewritten to support newlisp 10 changes



Can anybody summarizes what are the changes that need rewritting in order to comply with newlisp >= 10 ?



of course I can crawl the web but it would be nice if some one have a compiled list of changes
#14
Anything else we might add? / weirdness in newlisp
November 15, 2020, 04:02:08 PM
Hi,



I got again weird behaviour coding in newlisp.



I'm using  newLISP v.10.7.5 64-bit on Windows UTF8 libffi  using the NewLisp GS v.1.6

The downloaded zipped version  was a bit lower and then I downloaded the last exe and dll and overwrite the installed ones.



Now when I type this function in edit area of NewLisp GS or in REPL area, it is defined right:


> (define (utf8code c) (cond ((< c 128) "0xxxxxxx") ((< c 2048) "110xxxxx 10xxxxxx") ((< c 65536) "1110xxxx 10xxxxxx 10xxxxxx") ((< c 1114112) "11110xxx 10xxxxxx 10xxxxxx 10xxxxxx")))
(lambda (c)
 (cond
  ((< c 128) "0xxxxxxx")
  ((< c 2048) "110xxxxx 10xxxxxx")
  ((< c 65536) "1110xxxx 10xxxxxx 10xxxxxx")
  ((< c 1114112) "11110xxx 10xxxxxx 10xxxxxx 10xxxxxx")))


but if I add little pretty print to it, then everything goes wrong:



> (define (utf8code c)
(cond ((< c 128) "0xxxxxxx") ((< c 2048) "110xxxxx 10xxxxxx") ((< c 65536) "1110xxxx 10xxxxxx 10xxxxxx") ((< c 1114112) "11110xxx 10xxxxxx 10xxxxxx 10xxxxxx")))


ERR: missing parenthesis : "...(define (utf8code c) n"
> "0xxxxxxx"

ERR: missing parenthesis : "..."11110xxx 10xxxxxx 10xxxxxx 10xxxxxx"��e"


It seems newlisp is not able to figure out function definition is not complete because entering the REPL in command line I get:


> (define (f a)

ERR: missing parenthesis : "...(define (f a)n"


It seems like newlisp 10.7.5 only accepts one liners



Maybe is it a problem terminal not supporting unicode?   I tested with  windows cmd, windows powershell and mobaxterm (cygwin)
#15
I see there's no option to download newlisp-GS in new versions of newlisp and also don't include guiserver.lsp neither



is it deprecated in any way?