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

#1
$ more test.lsp

(println [text]

                                 x)

$ date

Tue Nov  3 17:31:28 WIT 2009

$ newlisp test.lsp



ERR: not enough memory

$ date

Tue Nov  3 17:35:17 WIT 2009

$ uname -rs

OpenBSD 4.6

$ dmesg | grep mem

real mem  = 1610117120 (1535MB)

avail mem = 1547059200 (1475MB)



it's weird, i got different result ... i'm on openbsd 4.6 i386 on amd64 cpu
#2
> (println [text]x)

~

ERR: missing end of text [/text]



ok in cli, however, not in .lsp file, try this

(println [text]

x)



or even this (forgot to type '/' in closing [/text])

(println [text]

x[text])



using (string) or (format  doesn't help either

(println (string [text]

         x))



(println (format [text]

         x))



top (on openbsd) shows a crawling but steady consumption of memory, eventually i get not enough memory error message
#3
> (date (date-value) 0 "%a %#d %b %Y")

"Sat #d Oct 2009"

> (date (date-value) 0 "%a %-d %b %Y")

"Sat -d Oct 2009"

> (date (date-value) 0 "%A %-d. %B %Y")

"Saturday -d. October 2009"



newlisp 10.1.5 on OpenBSD 4.5
#4
newLISP newS / (replace nil list-of-nil) hangs
May 17, 2009, 05:32:09 PM
> (set 'a '( 1 2))

(1 2)

> (replace 1 a)

(2)

> a

(2)

> (replace 2 a)

()

> a

()

> (set 'a '(true true))

(true true)

> (replace true a)

()

> (set 'a '(nil nil))

(nil nil)

> (replace nil a) ;hangs
#5
newLISP v.10.0.2 on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.



> (set 'q '("m4" "08" nil "rs" "vr" "vt" "m4"))

("m4" "08" nil "rs" "vr" "vt" "m4")

> (unique q)

("m4" "08" nil "rs" "vr" "vt" "m4")   ;note "m4" appears twice

> (sort q)

("08" "m4" nil "m4" "rs" "vr" "vt")   ;note "m4" nil "m4"

> (replace nil q)

("08" "m4" "m4" "rs" "vr" "vt")

> (unique q)

("08" "m4" "rs" "vr" "vt")
#6
newLISP newS / newlisp: SMS CDMA
July 20, 2008, 10:33:11 AM
I'd like to share my brief experiment with CDMA venus VT-21 modem (TIAN TUO XIN DIAN CDMA Technologies) for sending SMS



the modem works under windows (98/xp  tested) and linux (unreliable driver tho)



;COM4 from system property or /dev/ttyACM0 from dmesg

(set 'o (open "COM4" "update"))

;sending sms to 12345678 -- don't forget the r

(write-buffer o "AT*MB*MOREQ=0,12345678,,4098,TEXT TO SMSr")

;checking inbox -- again, don't forget the r

(write-buffer o "AT*MB*READTI=R,4098r"

(read-buffer o 'INBOX 102400)

(save "INBOX" 'INBOX)



The AT commands unfortunately are proprietary and differ from modem to modem; worse, not all CDMA devices (cellphones especially) have AT commands



I haven't used the code with GSM modem/phones mainly because I do not know how to connect to bluetooth device using newlisp (linux doesn't assign a node in /dev/ and i haven't tried it in xp ... no driver);



for now, ubuntu gui bluetooth+gnokii are sufficient for my GSM need so i won't actively look for solution



If you know how to use newlisp to talk to bluetooth devices, please let me know.  I love newlisp and would like to see it used in more places



thanks!
#7
newLISP newS /
March 05, 2008, 11:22:13 AM
oh yeah i forgot to mention that i have to adjust the time to my local time

say from 17:00 to 19:02 ... so i have to get 2 values



either select or slicing returns a list, not an element

(0 1 (parse t ":")) ;gives '("17")

(1 1 (parse t ":")) ;gives '("00")



so eventually i will need to use

(set 'hr ((parse t ":") 0))

(set 'mt ((parse t ":") 1))



i keep wondering, what function to use to extract an element from a list ... (first) comes to mind



i find inconsistency for (fist) .. (by accident, just now)



(set 'b '())

(if b (b 0)) ;gives '()

(b 0) ;list index out of bounds

(first b) ;gives nil ... shouldn't it give error too?



thx
#8
newLISP newS /
March 05, 2008, 06:45:53 AM
i'll have to dig the error event, thx



my recent case is that i have a newlisp program in remote server to get info about time from some website, write the time to a file to be served via ajax



after regex, the time string t can be say "17:00". "17", or ""



(set 'T (parse t ":"))

;;;T can be

("17" "00") ;(T 0) (T 1) work

("17") ;(T 1) break, program stops running

(); (T 0) break, newlisp stops



my fix was to use couple if statements

the older newlisp would probably give 17:17

which is okay, because at time 17:01, the whole program (if using older newlisp) would work as nothing happens ... accuracy is not very important in my case



newlisp stops fetching and updating the ajax file, that's big problem, especially at remote server, especially when my eyes are not on that ajax file
#9
newLISP newS /
March 05, 2008, 05:43:44 AM
yes, i do notice my code is less sloppier than it used to be

but now it consists of batallions of special cases

big, bulky code, mentally exhausting



is there any 'best practice' to avoid index out of bound cases, especially when u have less control over the list



basically i want my code to just run, not suddenly stops due to special rare case
#10
newLISP newS / list index out of bounds
March 05, 2008, 04:57:00 AM
can we have it graciously not to stop the running program?



personally i like the old way of returning the last element

it's because my program input can sometimes be an empty list (i have no control of my data source)



(set 'b '())

(b 0);program stops running

(b -1);progam stops running

(0 1 b);program stops running

(-1 1 b);proram stops running



i can put a condition of (if (= b '()) (do something)

but sometimes my input can be empty, one, or two elements

so my old codes of (input 2), (input 1), etc break

yes i can put conditions too

but that makes my program long and ugly

my past few weeks were of maintenance nightmare



my main gripe is that newlisp just stops running due to list index out of bound

it's like watching your favorite dvd and your software media player (being too smart) stops running due to a scratch

while the hardware dvd player (being dumb) just keep running the dvd till the end



sorry for my rants
#11
newLISP newS /
August 05, 2007, 02:09:21 AM
Quote from: "cormullion"looks like you can now do this!


Quote9.1.11 release notes

    negative second length in slicing now interpreted as offset

    from the right: (2 3 "abcdefg") => "cde", (2 -3 "abcdefg") => "cd"

    before negative length would be interpreted as going to the end


it's inclusive in left endpoint and non-inclusive at the right endpoint, similar to python



>>> a="abcdefg"

>>> a[2:-3]

'cd'

>>> a[2:]

'cdefg'

>>> a[2:0]

''



thanks Lutz!
#12
newLISP newS / slice negative counter
July 25, 2007, 04:17:48 AM
Hi all!



it's probably been discussed before but i haven't searched enough (i got the result on negative offset for slice)



is there any easy way to get negative counter act as position?

inclusive start and end

like:

(set 'a '(1 2 3 4 5 6 7))



(2 -2 a) ;want (3 4 5 6), newlisp gives (3 4 5 6 7)



in code:

(define (my-slice l s c)

   (if (>= c 0)

      (slice l s c)

      (slice l s (+ (length l) c -1))))



a; (1 2 3 4 5 6 7)

(my-slice a 2 -2) ;gives (3 4 5 6)

(my-slice a 2 0); gives ()

(my-slice a 2 2); gives (3 4)



it would be nice to have it in implicit slicing too like (2 -2 a)

thx!
#13
newLISP newS / matrix addition/subtraction/init
September 03, 2006, 02:14:58 AM
hi all



can we easily initialize a matrix by setting it to some array?

do we have matrix built-in function other than invert, multiply, transpose?

battery-included init, add, sub, determinant, size functions are nice to have



i played with matrix for a bit and i feel my code's long:



(set 'a (array-list (array 3 2 (sequence 1 6))))  ;matrix initialization

(set 'b (array-list (array 3 2 (sequence 4 9))))  ;array-list and array redundant?

(set 'c (array-list (array (length a) (length (a 1)) (map + (flat a) (flat b)))))

(invert (multiply (transpose c) c))

;((1.028645833 -0.8567708333) (-0.8567708333 0.7161458333))



this is my first time, sorry if the topic is old (i searched old posts tho)

thx!