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

#1
newLISP newS / A custom push-assoc
May 03, 2008, 01:02:31 PM
During the assoc discussion I came across a problem I'm sure I knew how to solve a year or two ago, but I can't figure out anymore.



I know I'll only have assoc lists of the form
((a (1 2)) (b (3 4)) ...)

I want to write a function like
(push-assoc key value assoc-lst)

The only way I could get it to work is if I instead had a global assoc-lst that I used.

(set 'alst '())
(define (push-assoc k v )
  (if (lookup k alst)
    (assoc-set (alst k) (list k (append (last $0) (list v))))
    (push (list k (list v)) alst -1)))


Any suggestions on how to make this so I can pass in the assoc-lst ?

I tried using a define-macro but failed.

I think I'm just missing something obvious.
#2
I'm working on adding some date syntactic sugar for newlisp.  Inspired by the ease of use of certain date manipulation in Ruby.



During my tests I noticed what i think is an issue in some of the date routines related to offset or possibly daylight savings time.  I tried to implement a newlisp version of http://snippets.dzone.com/posts/show/2099">days_in_month.



(Note: I'm in Austin, TX CDT which means my GMT offset is -0500 ==> 300 offset)



(Also note that if I use (date-value) without any options I don't need to specify an offset to get the correct datetime)


newLISP v.9.3.5 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> (date (date-value 2008 1 1) 300 "%Y %m %d")
"2007 12 31"
> (date (date-value) 0 "%Y %m %d"))
"2008 03 30"


Playing around a bit I found this


> (date (date-value) 300 "%z")
"-0500"
> (date (date-value 2008 3 1 0 0 0) 300 "%d")
"29"
> (date (date-value 2008 3 1 0 0 1) 300 "%d")
"29"
> (date (date-value 2008 3 1 1 0 0 ) 300 "%d")
"01"


It looks like there's some issue that can be solved by adding an hour.

Upon further investigation I found this


> (date (date-value 2008 4 1) 300 "%Y %m %d")
"2008 04 01"


That made me think - Daylight Savings Time issue (March 9th)


> (date (date-value 2008 3 8) 300 "%Y %m %d")
"2008 03 07"
> (date (date-value 2008 3 9) 300 "%Y %m %d")
"2008 03 08"
> (date (date-value 2008 3 10) 300 "%Y %m %d")
"2008 03 10"
> (date (date-value 2008 3 9 1 0 0) 300 "%Y %m %d")
"2008 03 09"
> (date (date-value 2008 3 8 1 0 0) 300 "%Y %m %d")
"2008 03 08"


It looks like doing historical date conversion doesn't take into consideration daylight savings time.  Also notice that I can't get access to what the timezone was before March 9th and adjust the offset accordingly.



My hackish workaround is to take the time at 3am.  

But I'm hoping there's a better way.  

So finally ... here's a newlisp days-in-month
(define (days-in-month y m)
  (set 'tmp (date (date-value) 0 "%z"))
  (set 'offset (+ (* (int (1 2 tmp)) 60) (int (3 2 tmp))))
  (if (= "+" (0 1 tmp)) (set 'offset (* -1 offset)))
  (int (date (date-value y (+ m 1) 0 3 0 0) offset "%d"))
)
> (days-in-month 2008 2)
29
> (days-in-month 2007 2)
28
> (days-in-month 2008 3)
31
> (days-in-month 2008 4)
30
#3
newLISP newS / newLISP on Noodles with Nettles
January 03, 2007, 04:21:56 PM
http://newlisp-on-noodles.org/wiki/images/3/3e/Nettlepasta.jpg">



I just released a module for working with the nettle cryptographic library.



http://newlisp-on-noodles.org/wiki/index.php/Nettles">http://newlisp-on-noodles.org/wiki/index.php/Nettles



Enjoy!



PS - I haven't been able to get it to work on Mac OS X. Nettle is in Fink but there's no dylib. If anyone knows how to make libnettle.dylib from libnettle.a I'd appreciate a tutorial in converting. For now it's been tested with Linux only.
#4
newLISP newS / Noodles
November 01, 2006, 01:11:36 PM
johnd and I have decided to publicly release the newLISP on Noodles wiki



http://www.newlisp-on-noodles.org">http://www.newlisp-on-noodles.org



In a nutshell, we want Noodles to be the "Ruby on Rails" of newLISP.



Right now we've got a few place holders for library and module development and some tips 'n' tricks.



Enjoy.



Gord
#5
newLISP in the real world / fork and sleep
May 10, 2005, 04:09:20 PM
Can someone explain to me why the following code does not sleep 5 seconds?

I have a hunch that a signal from the forked child invalidates the sleep - but I have no proof.

(define (SleepMe x)
  (println "Starting...")
  (fork (dotimes (y 10) (println y)))
  (sleep (* x 1000))
  (println "Why do you not sleep?")
)

(SleepMe 50)


Gord