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

#21
newLISP in the real world / -p some.lsp
March 31, 2004, 09:37:28 PM
Looking at manual:

newLISP as a TCP/IP server

newlisp -p 9090 some.lsp



when some.lsp is the one liner: (exit)

newlisp doesn't exit immediately but does once a connection is made with telnet. If the (exit) is in init.lsp then exiting is immediate. Is waiting until a connection before doing some.lsp the expected behaviour (this came up when I was wondering how to word the man page). If this is expected behaviour then change:



some.lsp is an optional file to be loaded during startup.



to:



some.lsp is an optional file to be loaded when connection is established.
#22
Anything else we might add? / ignoring init.lsp
March 31, 2004, 06:52:02 PM
Could there be a command line switch (eg -i) that suppressed reading the init.lsp file? That way I could

newlisp -i   special-init.lsp my-prog.lsp

to use a specific initialization file without having to fiddle with any init.lsp that happened to be around.

Or is there another way to get that effect?
#23
Anything else we might add? / integer conversions
March 21, 2004, 10:18:57 PM
currently:



> (integer 1)

1

> (integer "")

nil

> (integer nil)

missing argument in function integer

> (integer unbound 0)

value expected in function integer : nil

> (integer nil 0)

missing argument in function integer





Why are (integer nil 0) and (integer unbound 0) handled differently?



Lutz - would you consider allowing integer to return the default if the argument is nil? (would just tidy up some of my code - currently I check for nil prior to conversion).
#24
newLISP and the O.S. / rpm for newLISP 8.0
March 18, 2004, 03:28:14 PM
Hi Lutz,

As a major new stable release point is close perhaps now would be a good time to consider also releasing newlisp as an rpm for some systems (rehat/mandrake etc) or other distribution friendly package formats (Debian?).

If getting newLISP into a distribution is a target then providing this would maybe make things easier. I'd like to see newLISP in at least a specialist distribution (such as Quantian http://dirk.eddelbuettel.com/quantian.html">http://dirk.eddelbuettel.com/quantian.html ) for the next stable release. Having some functions especially set up for that distribution (eg some openMOSIX friendly process dispatch functions in a module/context  for Quantian) may help our case.



Having said that I've no experiance with rpm'ing packages.
#25
Anything else we might add? / P2P
March 17, 2004, 05:00:37 PM
Given newLISP's networking capabilities and its small footprint I thought someone may find this interesting - a very simple intro but helpful to me.



"Generic P2P Architecture, Tutorial and Example"



http://www.codeproject.com/useritems/Generic_P2P_Architecture.asp">http://www.codeproject.com/useritems/Ge ... ecture.asp">http://www.codeproject.com/useritems/Generic_P2P_Architecture.asp



Maybe someone would like to do a newLISP example?

Really just an expansion of the tk/newlisp connection.
#26
Consider:

CRADLE> (constant 'zz 10)

10

CRADLE> (define (tst n , zz) (begin (setq zz (+ n n)) zz))

(lambda (n , zz)

 (begin

  (setq zz (+ n n)) zz))

CRADLE> (tst 2)



symbol is protected : zz

called from user defined function tst

>



Without thinking too hard about it I expected a local zz not

to conflict with a constant zz
#27
newLISP in the real world / more info from sys-info
January 02, 2004, 03:16:52 PM
I've reposted this as a new thread:

Hi Lutz

Thank you for adding the -m N memory limiting switch to 7.4.1 in the development stream.

I've tried it with

(define (usemem n)(dotimes (x n) (set (symbol (string "nnn" x)) (sequence 1 1000))))

and newlisp stops very gracefully.



Could you make the memory restriction limit available via (sys-info) so that a program could potentially take action if the memory limit was approaching or so it could check prior to a memory intensive action?

(I realise that newlisp can't say that the memory will actually be available from the system)



Nigel
#28
Anything else we might add? / delete symbol from context?
December 30, 2003, 04:33:48 PM
Can a symbol be deleted from a context some way?

The reason for doing so may be that if a symbol is

created in a context before the same symbol is made global in main then the globalized symbol is never global to that context (can be accessed by MAIN:symbol of course). If that symbol could be deleted from the context symbol table then, presumably, the global symbol could be seen. This would allow cleaning up and in extreme cases perhaps save some memory.

Could a whole context be deleted (currently they are protected in main) once no longer needed eg a context that does only initialization stuff?

This reminds me of the FORTH forget of some of its dictionary.



Nigel
#29
This may be a problem with the tk front end rather than newlisp?

From the windows newlisp-tk v1.07 running 7.4.0 or 7.4.1 after opening the browser

<ctl-b> when you <ctl-t> to create a new context (or use menus) it

gives  error

wrong # args: should be "SelectContext browser contextName"

(one time this was followed by the error message

invalid command name ".browser.lbf.vat.lst") and then the context list can error Bad listbox index "" if clicked on. The context seems to be properly created in newlisp and is present when the browser is reopened.



Nigel
#30
In C I believe you can limit the maximum number of caharacters to be output from a string by using the precision part of the s format specifier.

eg see borland docs:

How [.prec] Affects Conversion



Char Type    Effect of [.prec] (.n) on Conversion



d   Specifies that at least n digits are printed.

i   If input argument has less than n digits,

o   output value is left-padded x with zeros.

u   If input argument has more than n digits,

x   the output value is not truncated.

X



e   Specifies that n characters are

E   printed after the decimal point, and

f   the last digit printed is rounded.



g   Specifies that at most n significant



G   digits are printed.



c   Has no effect on the output.

s   Specifies that no more than n characters are printed.



Newlisp doesn't recognise this (and doesn't claim to)

viz

> (format "%4s" "hello")

"hello"

> (format "%.4s" "hello")



problem in format string in function format : "%.4s"



> (format "%5.4s" "hello")



problem in format string in function format : "%5.4s"



> (format "%4.4s" "hello")



problem in format string in function format : "%4.4s"



>

 so there is no way within the format specification to limit string output size (it could be done by in the variable by slicing the string but it would be better to do it in the format I believe).



Could %s for format be easily extended that way?

I've put this in the win32 thread as I've not looked at the behaviour on linux.



Regards

Nigel
#31
Anything else we might add? / can we ungetc ?
December 22, 2003, 07:54:21 AM
In C programming sometimes to look ahead at the next file character a ch=getc(infile) is done and then if the logic requires that ch not be handled now a ungetc( ch, infile) is used to put the char back for later processing.

How feasible would it be to have the same facility available for (read-char

viz (unread-char ? I tried (write-char back into a file opened as update but that doesn't work. viz

> (set 'aFile (open "myfile.ext" "u"))

1

> (setq ch (read-char aFile))

97

> (write-char aFile ch)

1

> (setq ch (read-char aFile))

113

>



If it's not easy at the C source level for newlisp I'll try a getc & ungetc with defines or macros (anybody got such functions?).



I want getc/ungetc for a fairly 'no thinking please' C to newlisp port of a C program.



Regards

Nigel



Nigel
#32
Anything else we might add? / minus zero
December 17, 2003, 06:47:18 AM
I've noticed that:

> (ceil 0.0001)

1

> (ceil -0.0001)

-0

> (setq minuszero (ceil -0.0001))

-0

> minuszero

-0

> (= 0 minuszero)

true



The maths  I've tried minuszero with act as I'd expect

except perhaps

> (abs  minuszero )

-0

>



and (format doesn't like minuszero viz.

> (format "%d" minuszero)



data type and format don't match in function format : minuszero



> minuszero

-0

> (format "%x" minuszero)



data type and format don't match in function format : minuszero



>





Nigel
#33
newLISP in the real world / (abs ) crash with NaN
December 11, 2003, 04:18:38 PM
Giving newlisp 7.3.17

(abs (sqrt -1))

crashes newlisp -

so does

> (setq isnan (sqrt -1))

+NAN

> (NaN? isnan)

true

> (abs isnan)



I note in nl-math.c some code protects DIVIDE from Nan viz

#ifdef __BORLANDC__

         if(isnan(number))

            {

            result = number;

            break;

            }

#endif

         if(number == 0.0)

            return(errorProc(ERR_MATH));

         result /= number;

         break;



but not other functions

so (min (sqrt -1) 2) also "crashes".



I suspect it may relate to uncaught signals or exceptions from the math processor along the lines of the thread "math exception handling" http://www.alh.net/newlisp/phpbb/viewtopic.php?t=102">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=102



I've not tested all functions as to susceptibility to NaN problems - you

can probably see from the code which ones are at risk. In leu of catching

the signals etc perhaps more checking for NaN along the lines above used for divide is needed for robustness.



Nigel
#34
newLISP in the real world / passing pipe to process?
November 26, 2003, 06:58:12 PM
In the ref man it says:

syntax: (pipe)

pipe creates an interprocess communications pipe and returns the read and write handles

to it in a list. This function is only available on Linux/BSD compiles and not working on the

Win32 or CYGWIN versions.

(pipe) => (3 4) ; 3 for read, 4 for writing

The pipe handles can be passed on to a child process launched via process for inter process

communications.



QUESTION: How are the pipe handles passed to process (on linux of course)?



The man gives for process:

process

syntax: (process str−command)

process works similar to ! but in a non−blocking fashion, launching a child−process

specified in str−command and then returning immeadeately with true.

example:

(process "notepad") => true

See also pipe for interprocess communications.
#35
newLISP in the real world / ? current-line depreciated
November 18, 2003, 08:20:42 PM
In the newlisp docs (manual v7.3.3) it says about current-line:

current-line

syntax: (current-line) deprecated use $0



However, $0 is used as a return variable from regex -

is the "deprecated use $0" a documentation error?

Regards

Nigel
#36
newLISP in the real world / SIGFPE signal handling
November 17, 2003, 05:22:14 PM
Hi,

I've started a new thread as signal handling is the issue

 with (add 1e308 1e308) terminating newlisp.

Borland's default for catching a SIGFPE (floating point exception signal)

is program termination (that is, the library's action is a "feature" not a bug?).

From the borland help docs I pasted some code that catches the SIGFPE

and noew get:



newLISP v7.3.3 Copyright (c) 2003 Lutz Mueller. All rights reserved.



> (add 1e308 1e308)

Caught it!

1e+308

>

the diff format comparison below shows the inserted signal handling code,

I don't know if you want to include signal handling for the Borland compile

or write it off as a Borland 'feature'

Regards

Nigel

Examdiff Diff output: nl-math.c v7303 vs v7301

56c56,76

< int _matherr(struct _exception *e) {return 0;};

---

> int _matherr(struct _exception *e) {return 0;};

> /* try catch floating point exception signal */

> #include <signal.h>

>

> #ifdef __cplusplus

>    typedef void (*fptr)(int);

> #else

>    typedef void (*fptr)();

>

> #endif

>

>

>

> void Catcher()

> {

>    signal(SIGFPE, (fptr)Catcher);  //  ******reinstall signal handler

>

>    printf("Caught it!n");

> }

>

> /* signal(SIGFPE, (fptr)Catcher);  install catcher later*/

192a213

> #ifdef __BORLANDC__

193a215,216

>  signal(SIGFPE, (fptr)Catcher); /* install catcher */

> #endif

204a228

>    /*   case OP_ADD:            result += number; break; */
#37
newLISP in the real world / math exception handling
November 16, 2003, 05:21:16 PM
Hi all,

I've been looking into the math side of newlisp (that's my current interest in it) but

I don't see specified how newlisp handles floating point overflow exceptions.

From nl-math.c addition (for example) is done by:

CELL * floatOp(CELL * params, int operand)

{

double number;

double result;

double fltNum;

long intNum;



params = getFloat(params, &result);

if(params == nilCell)

   {

   if(operand == OP_SUBTRACT)

      result = - result;

   }

while(params != nilCell)

   {

   params = getFloat(params, &number);

   switch(operand)

      {

      case OP_ADD:            result += number; break



and early in the file there seems to be a "do nothing" exception handling established (fair enough default) viz:



#ifdef __BORLANDC__

int _matherr(struct _exception *e) {return 0;};

#endif



Now - causing an addition overflow crashes newlisp eg:



C:newlisp>newlisp

newLISP v7.3.3 Copyright (c) 2003 Lutz Mueller. All rights reserved.



> 1.7976931348623157E308

1.797693135e+308

> (add 1.7976931348623157E308 0.1e308)



C:newlisp>



I don't know what happens on linux. Can math exceptions be caught/handled in win32 newlisp? Could it gracefully die with an

error message? I don't have documentation on how

Borlands BCC55 uses matherr.

Regards

Nigel
#38
Anything else we might add? / regression test suite
November 10, 2003, 06:18:14 PM
Can anyone point to a lisp set of tests that test for reading of floats, their manipulation, and output. I've seen the GCL tests but they don't seem to test the basic number i/o. I was thinking of more a real world test (maybe read and manipulate data to give defined output file) or an extensive i/o test. Basically to do regression tests on new versions to maintain confidence that numerical i/o and processing is consistent across versions.

Nigel