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

Topics - starseed

#1
newLISP newS / mystery string bug ...
August 21, 2006, 10:23:34 AM
I don't understand, what happens here ...



Me being lazy I want a fast way to load a file ni the console, so I created the following, which tries to load a file by:

- converting the given file-name to a string and appending .lsp

- just converting to a string


(define-macro (do myfile)
  "tries to load the file given as a symbol, tries to append .lsp"
  (println myfile)
  (or
    (catch (load (println (string myfile ".lsp"))))
    (catch (load (string myfile)))
    (throw-error (string "file not found: " myfile))))

> (do tools.lsp)
tools.lsp
tools.lsp.lsp

problem accessing file : "tools.lsp.lsp"


I understand, that it can't load tools.lsp.lsp,

but after that it should just try tools.lsp, which seems not to happen ...

and I don't at all understand, where the tools.lsp.lsp in the error message comes from ...



(verson 8.9.6 Mingw)



Ingo
#2
newLISP newS / BUG: Crash with replace-assoc
August 21, 2006, 10:16:11 AM
I found a crash


newLISP v.8.9.6 on Win32 MinGW.
> (set 'test '((name "ingo")(last "Hohmann")))
((name "ingo") (last "Hohmann"))
> (push '(name1 "Whalesong") test)
(name1 "Whalesong")
> (replace-assoc 'name1 test (name1 "Starseed"))

invalid function in function replace-assoc : (name1 "Starseed")

(CRASHES)


The problem is related to the assoc replacement not being quoted.



Regards,



Ingo
#3
newLISP newS / [BUG] save non valid symbols (context)
August 20, 2006, 02:21:47 PM
Hi Lutz,



I created some symbols using sym, with strings which are really far from being valid symbols.


(context 'block)
(set 'my-list nil)
(set 'my-index nil)

(define (block:block)
   (my-list my-index))

(define (block:new alist)
   (let ((new-block (MAIN:new MAIN:block (gensym 'MAIN))))
      (new-block:init alist)
      new-block))

(set 'a (block:new))


With gensym creating symbols like:  _(-(_gensym_0.1_)-)_

And just for the fun of it, I tried to save this mess ...



This is what I found in the file:


(context '_(-(_gensym_0.1_)-)_)

(set (sym "_(-(_gensym_0.1_)-)_" _(-(_gensym_0.1_)-)_)
 (lambda () (my-list my-index)))


Of course, this won't load ...





Kind regards,



Ingo[/code]
#4
newLISP newS / Testing framework?
August 20, 2006, 01:23:28 PM
Hi All,



does anyone have a testuing framework for newLISP? I remember that I've seen some code posted with a test= function ...







Thank you,



Ingo
#5
newLISP newS / bug: hardcoded path in newlisp-tk?
August 18, 2006, 02:14:24 AM
Hi Lutz,



When I start newlisp-tk (newlisp 8.9.5), I get the following error:



Error sourcing /freewrap/newlisp-tk.tcl: couldn't execute "C:Programmenewlispnewlisp": no such file or directory



Which is quite OK, because it really doesn't exist, newlisp is

installed in E:ToolsNewlisp
#6
newLISP newS / [bug] lambda? scanning error ...
August 17, 2006, 08:37:23 AM
Hi Lutz,



I have defined the following func:


(define (type val)
   (if
      (float? val) 'float
      (integer? val) 'integer
      (lambda? val) 'lambda
      (list? val) 'list
      (macro? val) 'macro
      (string? val) 'string
      (symbol? val) 'symbol
      (atom? val) 'atom))


in a file called tools.lsp, now when I load this file, I get an error:


> (load "tools.lsp")

invalid lambda expression : [text]lambda
      (list? val) 'list
      (macro? val) 'macro
      (string? val) 'string
      (symbol? val) 'symbol
      (atom? val) 'atom))
#7
Hi,



I'm having a problem with a library call.

I'm still trying to get newLisp to use IUP(1), and now I have to call a function with a variable number of arguments, which expects NULL as the last.



And whenever I call the function, newLisp crashes.


(context 'iup)

(set 'iup-imports '(
   (iup.dll IupOpen IupDestroy IupClose IupSetHandle)
   (iup.dll IupSetLanguage IupGetLanguage)
   (iup.dll IupImage IupLabel IupDialog IupShowXY IupShow IupVbox IupHbox  )
   ;;;; CONTROLS
   (iup.dll IupButton IupMultiLine)
   ;;;; EVENT Handling
   (iup.dll IupMainLoop IupLoopStep IupFlush IupGetCallback IupSetCallback
            IupGetActionName IupGetFunction IupSetFunction
            )
   ;;;; ATTRIBUTE handling
   (iup.dll
      IupStoreAttribute
      IupSetAttribute IupSetAttributes IupSetfAttribute ;IupSetAttributeHandle
      IupGetAttribute IupGetAttributes ;IupGetAttributeHandle
      IupGetFloat IupGetInt
      IupStoreGlobal IupSetGlobal IupGetGlobal
      IupGetType IupHelp
      )
   (iup.dll
      IupVbox IupVbox IupZbox IupFrame IupAppend)
   ;;;;  pre-defined DIALOGS
   (iup.dll IupGetFile IupMessage IupAlarm IupScanf IupListDialog IupGetText
            )
   ;IupMessagef ???

   )
)

(define (setup )
  (dolist (dll-info iup-imports)
     (set 'dll-name (first dll-info))
     (dolist (func-name (rest dll-info))
         (import (string dll-name) (string func-name))))

   (set 'loaded true)
  )

(define (test-box)
   (IupOpen)
   (IupSetLanguage "ENGLISH")

   (set 'btn (IupButton "Test" nil))
   
   (print 'define-hbox)
   (set 'hb (IupHbox nil))
   ; --- the following line is never reached
   ; same with (set 'hb (IupHbox btn nil))
   (print 'define-dlg)
   (set 'dlg (IupDialog hb))
   
   (print 'show-dlg)
   (IupShow dlg)
   (IupMainLoop)
   (IupDestroy dlg)
   (IupClose)
)  

(setup)
(test-box)
(context 'MAIN)




Any idea what's happening here?





Thanks,



Ingo







(1) http://luaforge.net/projects/iup/">http://luaforge.net/projects/iup/
#8
newLISP newS / bug: newlisp-tk: new context
August 08, 2006, 01:54:19 PM
Hi, am I the only one who gets the following error?


Quotesymbol is protected in function silent : sym

called from user defined function SYS:make-context-verify


I get it when I try to create a new context through newlisp-tk (new context button).



P.S.: I get it with newlisp-tk as shipped with 8.9.0 and 8.9.3.
#9
I like to play at the console.



One thing I noticed at the newLisp console, is that prints and returns frequently run into each other, e.g.


> (define (test a) (print a))
(lambda (a) (print a))
> (test 5)
55


Why the hell is it printing 55??? Well, I found out quite fast, but with a little more complicated values, it may pose a problem.



Right now, I do return a nonintrusive symbol at the end of functions, which are solely meant to be used at the console:


> (define (test a) (print a) '-)
(lambda (a) (print a) '-)
> (test 5)
5-


What I would like to have, would be either

- an automatic return value marker, like
> (define (test a) (print a))
(lambda (a) (print a))
> (test 5)
5
== 5

- or a way to return something, that isn't printed at all, e.g.
> (define (test a) (print a) '-)
(lambda (a) (print a) no-print)
> (test 5)
5


Well, I can live without it ...





Ingo



P.S.: Edited, to get the bbcode markup ...
#10
Anything else we might add? / repl help system
August 03, 2006, 11:40:32 AM
I like to have an interpreter open, to check code snippets. Now, if the interpreter is already there, it would be nice to have an online help system ... here it is ;-)



(define-macro (def)
   "Creates a lambda expression, while checking for doc-strings"
   (let  ((__def_func (args))
           (__def_help ""))
      (dolist (val (rest (__def_func 0)))
         (if (string? val)
            (set '__def_help (append __def_help val)))
         (if (symbol? val)
            (set '__def_help (append __def_help "n   " (string val) "t - "))))
      (nth-set (__def_func 0) (clean string? (__def_func 0)))
      (set '__def_help (append (string (nth 0 __def_func)) "n" __def_help))
      (if (string? (nth 1 __def_func))
         (begin
            (set '__def_help (append __def_help "n" (nth 1 __def_func)))
            (pop __def_func 1)))
      (push __def_help __def_func 1)
      (push 'define __def_func)
      (eval __def_func)
   )
)

(def (help "get quick help on function"
      on-func "function you want help for")
   {displays the doc-string of a function
   if on-func is a string, it searches all symbols for occurrence of this string
   if on-func is nil, return a list of all lambda, macro-lambda and primitives}
   (if
      (nil? on-func)
         (filter (lambda (x) (or (lambda? (eval x))(macro? (eval x))(primitive? (eval x)))) (symbols))
      (string? on-func)
         (filter (lambda (x) (find on-func (string x))) (symbols))
      (lambda? on-func)
         (if (string? (nth 1 on-func))
            (begin
               (println (nth 1 on-func))
               '-)
            'not-documented)
      'not-a-lambda-expression
   )
)

Usage:

def - see 'help definition

help -
> (help help)
(help on-func)
get quick help on function
   on-func - function you want help for
displays the doc-string of a function
   if on-func is a string, it searches all symbols for occurrence of this string
   if on-func is nil, return a list of all lambda, macro-lambda and primitives
-
> (help "xml")
(xml-error xml-parse xml-type-tags)


And again, comments are appreciated.





Ingo
#11
OK, while I was thinking, and learning newLisp, and tried to implement a gensym a gensym. It does not technically give you an unlimited number of different different symbols, but it should be enough for most real world problems.



(context 'gensym)
(set 'no 0)
(define (gensym:gensym)
   "creates lots of unique symbols ... is that enough?"
   (sym (string "___" (inc 'no 0.1))))
   
(context MAIN)


And a macro to create hygienic macros, using gensym.



(define-macro (def-macro)
   "creates macro definitions with automatically created symbols"
   (let ((__def-macro_def (clean (fn (x) (= ', x)) (rest (args 0))))
         (__def-macro_sym '()))
      (dolist (__def-macro_ __def-macro_def)
         (push (list __def-macro_ (gensym)) __def-macro_sym))
      (set '__def-macro_def (expand (args) __def-macro_sym))
      (push 'define-macro __def-macro_def)
      (eval __def-macro_def)
   )
)


Disclaimer: I'm a newbie when it comes to newLisp (and the whole lisp family), so take my code with a grain of salt. ;-)



Comments are highly appreciated.



Ingo
#12
Anything else we might add? / pipes and blocking read
August 02, 2006, 03:10:47 PM
When using pipes, read is blocking.

Is there a way to check for available data, before trying to read?

From the help file, peek seems not to work, and when I try

(peek ((pipe) 0))

I get "invalid function (peek ((pipe) 0))
#13
Anything else we might add? / current-dir?
August 01, 2006, 02:25:15 PM
Hi all,



just an easy question, or so I hope, how do I find out about the current dir in newlisp? I haven't been able to find it in the docs.





Thanks,



Ingo
#14
Anything else we might add? / Problems with the forum?
August 01, 2006, 01:13:41 PM
Is it only me who has frequent problems to post here?



I normally get "The requested service is temporarily unavailable" messages, though I see others posting.
#15
Hi,



what do I have to do, if I want to add a new function to newlisp, with an implementation on the C-side of things?



I guess I've found out, that, e.g. p_and in newlisp.c is the implementation of and in newlisp. But I'm missing the link between the two.



Where do I have to look?



TIA,



Ingo
#16
Hi,



I'm toying around with newlisp, and am trying to use IUP [1] for gui creation.

I have been able to show something (hooray! ;-), and the interesting part will be to add callbacks to buttons, etc.



How does newlisp-tk handle this? I guess there's a function added to the tk side of things?



I have skimmed through the sources, but haven't been able to find the right place to look at. I'm not too fluent in C, and not at all in tk, this may be part of it ...





If you some pointers to enlighten me, it will be highly appreciated.





Kind regards,



Ingo





[1] http://www.tecgraf.puc-rio.br/iup/">http://www.tecgraf.puc-rio.br/iup/