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

#31
newLISP newS / Re: Updated links for modules page
January 24, 2012, 06:06:18 PM
Your links on the navbar do not point to anything, they have the hashmark.
#32
Quote from: "jopython"How about html templating module?


Haven't used it yet, but Jeff Ober's http://static.artfulcode.net/newlisp/web.lsp">web module claims to have ASP/PHP-style templates. Also I think I've seen some other stuff around with template capabilities.
#33
Since we're in this time of the year, I'll take advantage of it and make some wishes for newlisp.



First I'll wish there's a new area for wishes like this. Could it be a new forum area or a bug tracker, so we can keep track of what has been proposed and avoid discussing things that have already been discussed. Also to know the status of things under implementation.



That was a meta-wish. Now what I would like to have implemented in newlisp:



[*]tab completion working not only on newlisp's primitives but also on loaded modules and new defined symbols inside REPL.

  • [*]in debug mode I wish ENTER to issue s+ENTER so one can press just a single key to advance in step mode. A better option would be to give it auto-configuration, that is: to have a default binding of ENTER to s, but also change default on every new command, so the next ENTER keypress without command would issue last issued command (step, next or cont).


  • [*]error messages with line numbers referring to script file. I know this has been http://newlispfanclub.alh.net/forum/viewtopic.php?f=5&t=67">already discussed, but I think it's a necessary addition. Sometimes you have very similar lines of code, or equal, on different parts and the message is not enough to find the offending line. Recently I had to fill my code with printlns to hunt a bug. Regarding the bloating Lutz mention on linked post, I'd say we could have different modes. So in debugging mode newlisp would be bloated, but not in production mode. Not sure though if two different binaries are necessary or if it could suffice to have a command line switch.


  • [*]parenthesis highlight inside REPL would be very nice


  • [*] remove the need to put [cmd] tags or press ENTER to issue an auto [cmd]. If [cmd] tags are necessary for something else, then don't remove them, but make multi-line code work from the beginning. I knew about the press ENTER trick recently and I think is somewhat hidden and feels unnecessary.


  • [*]a centralized repository endorsed by newlisp wich allows collaborative building of code snippets.
  • [/list]
    #34
    I'm not sure I fully understand what you're trying to achieve. However I can tell you that you avoid name conflicts by using http://www.newlisp.org/downloads/newlisp_manual.html#contexts">contexts.
    #35
    Thanks, I used ++ to keep the section. Also modified it a little bit to make emphasis on the implicit conversion both inc/dec and ++/-- do.
    #36
    I just added the notice to avoid using curry with destructive functions in the chapter http://en.wikibooks.org/w/index.php?title=Introduction_to_newLISP/Apply_and_map&stable=0#currying">Apply and map which is the first one to mention curry function.



    However I stomp on something when I went to edit the section http://en.wikibooks.org/w/index.php?title=Introduction_to_newLISP/Working_with_numbers&stable=0#Invisible_conversion_and_rounding">Invisible conversion and rounding. See, the thing is cormullion wrote that section to tell about inc and dec converting floats to int when no step was provided. But I noticed newlisp v10.3.3 does increment and decrement without converting floats to ints.



    cormullion stated:

    (inc 2.5) ; gives 3, not 3.5 as expected

    But that's not true anymore on v10.3.3:

    (inc 2.5)
    3.5

    So the question is:



    A.- Should I erase the whole section since the behavior has changed?

    B.- Or are there other functions that still make the conversion from float to int and can be used to exemplify the issue?
    #37
    Quote from: "jopython"What is the ITN book?

    I mentioned the full title in the first message: ITN book is http://en.wikibooks.org/wiki/Introduction_to_newLISP">Introduction to newLISP book. It's linked in newlisp.org documentation, I thought it was pretty known in the community.
    #38
    Quote from: "Lutz"Destructive functions should not be used with curry...

    This will be mentioned in the reference manual for 'curry' and should also be mentioned in the WikiBooks introduction.


    Cool. I'll be updating ITN book in a couple of hours, I need to take a nap now.
    #39
    newLISP in the real world / Re: getting error from open
    December 22, 2011, 09:19:58 AM
    Quote from: "Lutz"On this simpler program:

    ...

    I cannot repeat the behavior, you are seeing (incrementing of file handles).


    Yes, called directly it behaves fine. So I rolled back my git repo and uploaded the bogus version with some additions to denote the bug.



    I put it here: https://gitorious.org/bogus-stuff/dzenbar-bogus">//https://gitorious.org/bogus-stuff/dzenbar-bogus



    (I realized just now, when replying this message, that I could have attached the code to the message)



    Run status and you'll get increasing file handles. Run try.it.alone.lsp and you'll see the (almost) same code (parse-stat-line replaced with a println) behaving ok, like in your simpler script.



    Also I included an error.log which is a full run of status until it blows up.


    Quote from: "Lutz"
    ps: also - unrelated - why are you using 'do-while' instead of 'while'. Shouldn't the regex test take place always after reading a line from the file?


    Because I'm a moron! :P



    In fact I had a while before, but had what I thought was a convoluted exit condition, you can check it out with

    git log -p 48317b302b67e820e8d0a9816267d5a42c68f16e

    The thing is that in theory is wrong, but in practice it seems I'm setting something somewhere that avoids parse-stat-line from exploding. And since it doesn't blow up, it's unseen since this runs once per second.
    #40
    I'm reading now the chapter Working with numbers from Introduction to newlisp book, and in the third code example under the subtitle Invisible conversion and rounding we see:

    (set 'lst '(2 6 9 12))
    ;-> (2 6 9 12)
    (inc (lst 0))
    ;-> 3
    lst
    ;-> (3 6 9 12)
    (map inc lst)
    ;-> (4 7 10 13)
    (map (curry inc 3) lst)
    ;-> (6 9 12 15) ; === CHECK OUT THIS LINE ===
    lst
    ;-> (3 6 9 12)

    But on v10.3.3 I get the map+curry operation to work on the list like this instead:

    newLISP v.10.3.3 64-bit on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.
    > (set 'lst '(2 6 9 12))
    (2 6 9 12)
    > (inc (lst 0))
    3
    > lst
    (3 6 9 12)
    > (map inc lst)
    (4 7 10 13)
    > (map (curry inc 3) lst)
    (6 12 21 33) ; === CHECK OUT THIS LINE ===
    > lst
    (3 6 9 12)

    It's taking the number by pairs and adding them instead of increasing them individually by 3 (except the first one).



    Now I recall reading about a function that takes elements by pairs, can't recall the name right now, but recalling that it exists confuses me on this behaviour. Is it expected? Is map+curry+inc supposed to take the list elements in pairs and operate them with one another? I feel it shouldn't, but I may be wrong.



    Doing...

    newLISP v.10.3.3 64-bit on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.
    > (set 'lst '(2 6 9 12))
    (2 6 9 12)
    > (map (curry inc 3) lst)
    (5 11 20 32)
    > lst
    (2 6 9 12)
    > (map (lambda (x) (+ x 3)) lst)
    (5 9 12 15)
    > (map (lambda (x) (inc x 3)) lst)
    (5 9 12 15)
    > (map (curry + 3) lst)
    (5 9 12 15)

    ...works as expected. So now I see the curry+inc is the issue.



    What's going on? Should I update ITN book and denote the pitfall as expected behavior or should this behavior be modified?
    #41
    newLISP in the real world / getting error from open
    December 22, 2011, 04:15:32 AM
    I'm using http://i3wm.org/">i3 with https://sites.google.com/site/gotmor/dzen">dzen bar and I'm using newlisp to build me a pretty customized bar.



    I have this code to check for cpuload:

    (define (read-proc-stat)
        (setq procStat (open "/proc/stat" "read"))

        (do-while (regex {cpud?} (read-line procStat))
            (parse-stat-line (current-line)))
        (close procStat))  

    Script runs ok for a while, with a (sleep 1000) between calls, and then spits this:

    ERR: value expected in function read-line : procStat
    called from user defined function read-proc-stat
    called from user defined function draw-cpu-load

    I added a (println procStat) and found script stopped when procStat would take value 1024, so it sounded like I was hitting an OS limit there. So I wrote a new script to test that:

    (define (read-proc-stat)
        (setq proc-stat (open "/proc/stat" "read"))
        (println "open handle: " proc-stat)                                                                                                                                  

        (do-while (regex {cpud?} (read-line proc-stat))
            (println (current-line)))
        (close proc-stat))

    (while true
        (read-proc-stat)
        (sleep 1000))

    With this script the opening handle remains constant (at value 4 in my test).



    The difference with the "real" script is that I have a status script that loads a cpuload module which contains read-proc-stat function definition.



    I wonder why same function gets a constant handle when I call it one way and an incremented one (in steps of 4) when I call it the other way.



    I modified read-proc-stat like this:

    (define (read-proc-stat:read-proc-stat)
        (if (nil? read-proc-stat:procStat)
            (setq read-proc-stat:procStat (open "/proc/stat" "read")))

        (do-while (regex {cpud?} (read-line read-proc-stat:procStat))
            (parse-stat-line (current-line)))
        (seek read-proc-stat:procStat 0))


    Which fixed the issue. But now I wonder: since I'm not closing the file ever, does newlisp close opened file handles when script finishes? What if it finishes with ctrl-c or what if it explodes on some other part? Does it do a proper cleaning?
    #42
    itn book updated now. I modified examples and part of the text under subtitles: FOOP in a nutshell, Polymorphism, Modifying objects.



    Also I added an external link to the reference manual since there's an example there on nested objects which I felt was important and is missing on itn book. Maybe we should add another section to show that or maybe just leave the link.



    Feel free to review this newbie's changes, and if you do, make sure I didn't mess it all.
    #43
    Thanks Michael and Lutz, I think Cormullion said somewhere in the book to read the reference manual first, not sure though, and now I'm too engaged with the book to start from scratch with the manual. Anyway I should read it when I find this kind of differences, I'm making a mental note now.



    A question on style now, regarding the example under the subtitle "Structuring a larger FOOP program" in the newlisp manual, shouldn't class declaration go inside each class defining file?



    We got in main:



    (new Class 'Rectangle)
    (new Class 'Circle)


    And I wonder if shouldn't be better to have each of those inside 'Rectangle.lsp' and 'Circle.lsp' respectively.



    BTW, I'll be updating itn book in a couple of minutes.



    Update



    I knew I was forgetting something: the old way to call functions using full name is forbidden now, right?



    (SomeClass:some-function) ; doesn't work on newlisp version >= v10.2
    #44
    I'm reading the chapter on contexts now on the Introduction to Newlisp book, and just copy pasted the example on FOOP, which looks like this:



    ; definitions

    (define (Time:Time (t (date-value)) (zone 0))
    (list Time t zone))

    (define (Time:show t)
    (date (t 1) (t 2)))

    (define (Time:days-between t1 t2)
    "Return difference in days between two times."
    (div (abs (- (t1 1) (t2 1))) (* 24 60 60)))

    (define (Time:get-hours t)
    "Return hours."
    (int (date (t 1) (t 2) {%H})))

    (define (Time:get-day t)
    "Return day of week."
    (date (t 1) (t 2) {%A}))

    (define (Time:leap-year? t)
    (let ((year (int (date (t 1) (t 2) {%Y}))))
    (and (= 0 (% year 4))
    (or (!= 0 (% year 100)) (= 0 (% year 400))))))

    ; use

    (set 'time-now (Time))
    (set 'my-birthday (Time (date-value 2008 5 26)))
    (set 'christmas-day (Time (date-value 2008 12 25)))

    ; call functions with full context prefix
    (println (Time:show christmas-day))

    ; or call them with colon prefix mode
    (println (:show christmas-day))


    Last call gives me this error:



    $ newlisp foop.lsp
    Wed Dec 24 21:00:00 2008

    ERR: invalid function in function date : (MAIN:t 1)
    called from user defined function Time:show


    I tried switching to the context, just to check cause there will be no fun if you have to do that, but I wanted to check it anyway:



    > (context Time)
    Time
    Time> (set 'christmas-day (Time (date-value 2008 12 25)))
    (Time 1230163200 0)
    Time> (:show christmas-day)

    ERR: invalid function in function date : (MAIN:t 1)
    called from user defined function Time:show


    What I understood about colon prefix mode was that it decided which function to use based on the class found in position zero. So I though maybe this version was messing with the contexts and tried also this definition for 'show' function:



    (define (Time:show Time:t)
        (date (Time:t 1) (Time:t 2)))


    Which gives almost the same error:



    $ newlisp foop.lsp
    Wed Dec 24 21:00:00 2008

    ERR: invalid function in function date : (t 1)
    called from user defined function Time:show


    'MAIN' disappeared, but we still got the same error. So it's like 'show', when called with the colon prefix mode, it's not receiving a list inside 't'.



    I don't know if this is something that has changed since that part of the book was writing or if I'm missing something. Any thoughts are welcome.
    #45
    Quote from: "Lutz"
    The system variable $it is mentioned in the 10.3.3 doc

    http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols">http://www.newlisp.org/downloads/newlis ... em_symbols">http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols


    Sorry about that Lutz, my bad. I just went for the index instead of searching and now I'm noticing that the index is for functions and that there're plenty of mentions of $it.


    Quote from: "Lutz"
    A change in the WikiBook Introduction is not necessary.


    Should it mention the different behavior (pre and post v10.3.8) ?