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

#1
newLISP newS / Re: TCL
November 09, 2012, 08:15:12 AM
Quote from: "kindmoji"Hi  dear friends ,

I want to know if anyone knows " TCL " (tool command language) programming , and what is the differences


On Tcl



I work with Tcl at work, but the version we got at work has a lot of niceties, but it's still a Tcl engine. Tcl is a fine language for systems applications rather than web IMHO.  However, it does have a http module if you are interested in writing CGI scripts, which run server side. There's a Tcl plugin to run applets in a web browser, but I'm sure that it's so obscure and nobody uses it.  The core language is an imperative language with a similar syntax to Perl or C. There have been Object Oriented extensions written on the language, and there are many plugins available. If you want to get a lot of information on Tcl, head to http://tcl.tk">//http://tcl.tk.



On Web Development



I agree on the choices of languages written by Lutz in terms of learning a language for Web Development. However Web Development is a discipline rather than a given technology and it depends a lot of what you want to do.



There are three things that you need to know to perform effective web development.



[*] HTML/XHTML
  • [*] CSS

  • [*] JavaScript
  • [/list]


    The rest depend on the technology  of the system that you are working with. All of these provide similar facilities for web development with certain degree of features provided for a given task.



    [*] JSP Engines
  • [*] LAMP/WAMP stacks

  • [*] ASP, ASP.NET

  • [*] DragonFly

  • [*] CGI Scripting

  • [*] Ruby on Rails

  • [*] Django
  • [/list]


    All these are web engines that will run server side. They require a specific set of technology to write programs on the web. You should read on these and get familiar on the technology that interests you.



    On Tcl vs newLISP



    The question is what would be easier for a newbie , the answer usually lies, depends on the newbie. :) If you come from a shell scripting or C development background you will find the Tcl syntax more familiar than newLISP. If you come from a Scheme background, then newLISP will look more familiar than Tcl. In terms of learning curve, they are both equally bad.  :).



    I personally do a lot of development on both. However, all my personal development is done in newLISP. It is probably because I need to endure Tcl on a daily basis that my mind needs a break. :)
    #2
    So, what can you actually DO with newLISP? / Lorem Ipsum
    November 08, 2012, 04:49:08 PM
    Dolor sit amet...



    ;; This code is in newLisp
    ;;
    ;; Use the lipsum generator to generate Lorem Ipsum dummy paragraphs / words / bytes.
    ;;
    ;; Lorem Ipsum courtesy of www.lipsum.com by James Wilson
    ;;
    ;; @param what in "paras","words","bytes"]
    ;; @param amount of paras/words/bytes (for words minimum is 5, for bytes it is 27)
    ;; @param start always start with 'Lorem Ipsum' "true"/"false"

    (define (lipsum what amount start)
       (setq lipsum-buffer (get-url (format "http://www.lipsum.com/feed/xml?what=%s&amount=%d&start=%s" what amount start)))
       (setq lipsum-list (xml-parse lipsum-buffer 7))
       (nth 1 (first (nth 2 (first (nth 2 (first lipsum-list)))))))


    (lipsum "paras" 2 "true")
    #3
    Hi:



    It's been a while since I've played with Geany's configuration files.



    [*] keywords vs. special keywords = one color vs another color. It will be probably up to your taste to decide one vs another and see how colorization helps you. I took a look at the newlisp.el and all the keywords are in "keywords".  What you can do is to take, for example predicates, and put it in special keywords to distinguish them, or define or define-macro to make it easier to identify function definitions. It's probably one of those things that you should play around and find what you like. :)
    [/*]
  • [*]
    What would I change? Default extension, you might want to use .lsp than .lisp. run_cmd from clisp (common LISP) to newlisp, of course.
  • [/list]
    #4
    Speaking of GitHub repositories.



    I have been adding xymon/hobbit/bb monitoring scripts in https://github.com/papoanaya/monitor_newlisp">//https://github.com/papoanaya/monitor_newlisp . I've been coding them to monitor different components at home. If you're familiar with Xymon, you'll see that the structure used is similar to other scripts written in other languages.



    These were built for my use, but feel free to tinker with them.
    #5
    It looks interesting, thanks to Wendal for posting examples because my Chinese is non existent :)
    #6
    Hi:



    While working in a client site I had to port the  shell scripts used by the wmii window manager to newlisp. They are available at github.com. (https://github.com/papoanaya/wmii_newlisp">https://github.com/papoanaya/wmii_newlisp), if you want to play with them.



    These programs uses newlisp to handle the wmii window manager; a stacking window manager which is available at http://wmii.suckless.org">http://wmii.suckless.org. The wmii window manager uses an external libixp wrapper for inter process communications.



    Documentation is available at the github.com repository, hopefully it makes sense.



    Luis
    #7
    newLISP in the real world / On Macros
    April 21, 2012, 01:28:32 PM
    Hi:

    One post in comp.lang.lisp stated that "thou shall know macros to get thy mastery of ye LISP arcana", hence decided to explore macros for fun and amusement. Sadly here in the forum if you do a search on  macro (or define macros) nothing shows up, hence decided to write a small post about macros.



    (define-macro ) in newlisp creates functions in which the arguments are not evaluated. In lay person terms, f you have a variable x with a value of 10, and x is being passed to a macro, then "x" is the value that is obtained from the argument and not 10.  You can look for fexpr in your favorite search engine for the details on implementation and how it differs from macro in common lisp.  More details can also be found in the newlisp manual.



    Well,  this sounds nice and dandy, but what can you do with such thing.



    I'm placing two examples of macros that come directly from the gnulisp manual. Only that they are implemented in newlisp (obviously :) )  It really does not have a lot of changes from the examples as written in the text.



    The first one is  an implementation of the "inc" function using macros:




    (define-macro (my-inc var)
      (eval (list 'setq var (list '+ 1 var) ))
    )

    (while (< i 10)
           (println (my-inc i))
    )


    The following must be noted:

    [*] The macro is building code that will be evaluated. In this case, it is building

    a list containing (setq i (+ 1 i))

  • [*] For the macro to execute, the created expression must be evaluated. If you

    substitute eval with println, you'll see aforementioned code. This is handy to

    debug macros.  An alternative of execution is to return the resultant list and

    modify it, but in this case, I wanted it only to execute; printing the numbers from 1 to 10.
  • [/list]

    The second example is a version of the for loop with syntactic sugar.




    (define-macro (mi-for var from init to final do body)
      (eval
      (list 'let (list (list var init))
            (cons 'while (cons (list '<= var final)
                               (append (list body) (list (list 'inc var))))))) )

    (mi-for i from 1 to 10 do
         (let ()
           (println i) )
    )



    [*] As you can see, it's another variation of the same theme. In this case

    it is building a while loop that will execute 10 times the content of the

    body.
  • [*] Being that the body is only one argument, it needs to be surrounded with a let

    function for all the statements to run.

  • [*] Eval is used to execute the code within the macro, but if substituting the eval with a println, this is what is obtained.
  • [/list]



    (let ((i 1))
     (while (<= i 10)
      (let ()
       (println i))
      (inc i)))


    This means that code can be built in a macro, returned from it and

    executed later on in your code.



    Hopefully this will help to those that are trying to understand these and hopefully find these examples useful.
    #8
    Ok, the following is a continuation on the code.



    The problem that I was having with the original code is that newlisp was not terminating when dzen2 exited. The issue resides in the way xdm collapses the session and was not killing the newlisp process. Even though you may keep the process id to remove the process, there are times that you might want to terminate the newlisp code if the subordinate process is not longer running.  



    The following function runs "ps" and returns if a given process is running or not:




    (define (process_exists the_pid)
      (setq get_process (exec "ps"))
      (not (for-all
       (fn (x)
         (not (= the_pid (first (parse x))) ))
       get_process) )
    )



    You might want to note the way "for-all" is used being that it is using negative logic to determine if a process is running. Rather than checking if the process is there, it is checking that the process is not running and then reverse the result prior to exit.



    This allows to scan the whole process table and obtain the desired result without having to parse through the whole result list to get it.



    This function gets incorporate in the main loop on the previous code as follows:




    (while (not nil)
    ;...
    (if (not (process_exists (string pid)) )
        (throw 0))
    )
    ;...
    )



    The returned PID is a number and the PID that returns from (first (exec "ps")) is a string.  The type conversion can be done in either direction, but I choose to convert to string. Perhaps converting to integer would have been more efficient, but on a 10 seconds loop, there's not much of a difference.
    #9
    Hi:



    Well, you try to solve a problem with the best tool available. I do have some of the alternate code available but the objective was to parse code from externally called programs.



    One thing I forgot was to show a screenshot, with apologies for the pogoplug advertisement.

    http://ppl.ug/36KmI1CcORc/">//http://ppl.ug/36KmI1CcORc/



    The indicators that are managed by newlisp are in the upper right hand corner.



    Luis
    #10
    Hi again



    It's been a while, but I still use new lisp for various things as time permit. In this case this is more of a study in system or utilities  than anything else.



    One piece of software I've been dabbling of late is called dzen2. For more information you can go to http://sites.google.com/site/gotmor/dzen">//http://sites.google.com/site/gotmor/dzen. Dzen2 is a generic information application akin to conky, but it does not contain any intelligence in terms of monitoring. It accepts information from system input and display them in X. It has some auxiliary programs available for use that are used to create bars and menus.



    What I did was to write a small monitoring application for dzen in newlisp in which gathers monitoring data and display them into dzen through the use of pipes. The annotated code is here and hopefully it will make sense.



    One thing I noticed while writing this even though I've used perl and dabbled with scsh, newlisp is not slouch when it comes of handling output from command line tools in which a lot of output manipulation can be effectively done with fairly little code.  Hopefully it'll be evident in the enclosed program.



    #!/opt/home/papo/bin/newlisp
    ;; Appareance
    ;; NOTE: Although these can be used, the only one really in use is
    ;; SEPARATOR.

    (define BACKGROUND-COLOR "'#2c2c32'")
    (define ALTERNATE-BACKGROUND-COLOR "'#494b4f'")
    (define FOREGROUND-COLOR "'grey70'")
    (define SEPARATOR "^p(3)^r(3x3)^p(3)")
    (define FONT "fixed")


    ;; DZEN requires to have regular updates. Even though this is not use
    ;; right now it is set up every 10 seconds.

    ;; Main loop interval in seconds
    (define SLEEP-INTERVAL 1)


    ;; Signal handler to exit and not to get stuck in debug mode.

    (constant 'SIGINT 2)

    (define (ctrlC-handler)
      (exit)
    )

    (signal SIGINT 'ctrlC-handler)


    ;; This gets the results of df

    (define (get-disk)
      (setq df-results (exec "df"))
    ; The map is used to get the attributes that we want to monitor.
      (map (fn (x)
    (let ((y (parse x)))
      (list (nth 0 y) (nth 4 y))
    ))
    ; Using rest removes the header in one swoop.
    (rest df-results))
    )

    ;; There is a better way by writing using format, but I'm being lazy
    ;; This executes gdbar and get a graphical representation of a dzen bar.
    ;;

    (define (get-dbar fs per)
    ; By duing first, we get the string needed to write the bar

       (first (exec  (append "echo " per "| gdbar -l " fs) ))
    )

    ;
    ; This will iterate from the df results and only
    ; get the bar to the ones we care about. In this case
    ; only the ones mounted in cemnt. This can be changed, of course.


    (define (get-dbar-results)
      (let ((df-result (get-disk)) )
        (map (fn (x)
      (if (not (nil? (find "cemnt" (first x)) ))
          (get-dbar (last (parse (first x) "/"))  (nth 1 x)) ))
    df-result))
    )

    ;;
    ;; Same for the memory, get the results from free;
    ;;

    (define (get-free)
      (setq free-results (exec "free"))
    ; We only need the totals that are at the end.
      (parse (last free-results))
     )

    ;;
    ;; We get the bar by computing the percentage of
    ;; Free / Total
    ;; And get the resultant bar representation.
    ;;

    (define (get-mem-dbar-results)
      (setq free-result (get-free))
      (get-dbar "MEM:"
      (string (round (mul
    (div
     (float (nth 2 free-result))
     (float (nth 1 free-result))) 100 ) 0) ) )
    )


    ;
    ; Main
    ;

    (define (main)

    ; These pipes are used to communicate the results to the dzen2 process
    ; This way results are display without annoying blinks.
    ;

      (map set '(myin bcout) (pipe))
      (map set '(bcin myout) (pipe))

    ; Call dzen2 in the background, we only need bcin pipe.

      (setq pid (process "dzen2 -bg gray10 -x 200 -p -ta r  " bcin 0))

    ; Main loop, what it does is
    ; get the statistics and write them into
    ; the dzen2 process

      (while (not nil)
    (map (fn (x)
       (if (not (nil? (find "sd" x)))
    (write myout (format "%s " x))) )
      (get-dbar-results))
    (write myout SEPARATOR)
    (write myout " ")
    (write myout (get-mem-dbar-results))
    (write myout " ")
    ;
    ; dzen2 provides a gcpu bar.  In linux, you can create a process
    ; that reads from /proc. But I'm being lazy being program does the work.
    ; gcpubar works akin as vmstat, you need to get the second one
    ; to get an actual measure. In this case, there are 5 iterations
    ; and the last one is selected.

    (write myout (last  (exec "gcpubar -i 1 -c 5  ")))
    (write-line myout)

    ; Wait 10 seconds

    (sleep 10000)
    )
    ; Probably these should be moved in the signal handler.

      (destroy pid)
    )

    ;Start here.

    (main)

    #11
    Not that I am familiar with it, but it would entail configuring it to identify .lsp extensions as executables and make sure that all your cgi are have execution priviledges with a !# indicating the location of the interpreter. Perhaps as al alterntive would be to use new lisp as a surrogate server and invoke functions from the web server, that is more complicated though.  You can also code a module being that it is only one call to execute the interpreter.



    It is up to you to determine how crazy you want to go.
    #12
    I was dabbling one night and I decided to translate the code to create sequence diagrams from websequencediagrams.com from python to newLisp.



    The code might need some improvement, but it does work for me.





    ;;
    ;; Web Sequence Diagram Interface
    ;;

    (define (url-encode str)  
        (replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0))


    (define (url-decode str)
        (replace "+" str " ") ; optional
        (replace "%([0-9A-F][0-9A-F])" str (format "%c" (int (append "0x" $1))) 1))


    (define (getSequenceDiagram text outputfile (style "default") )
      (set 'request (list (eval 'text) (eval 'style)) )
      (set 'urladdress "http://www.websequencediagrams.com/index.php")
      (set 'urldata (join (list "message=" text "&style=" (url-encode style) )))
      (set 'result (post-url  urladdress urldata ) )
      (set 'expr (regex "(\?img=[a-zA-Z0-9]+)" result ))
      (if (nil? expr)
          (write-line "Something went wrong")
          (let ()
             (set 'image (get-url (join (list "http://www.websequencediagrams.com/" (first expr) ) )) )
             (write-file outputfile image)  
          )
      )
    )

    (getSequenceDiagram "alice->bob: authentication request n bob-->alice: response" "c:\out.png" "qsd")

    #13
    newLISP and the O.S. /
    November 14, 2005, 07:02:02 AM
    Quote from: "Lutz"No way to do OLE/COM with newLISP and most likely never will be. OLE/COM is very complex and requires a lot of code to implement.



    Lutz


    That's ok, I can get by with loading dll's.  That's a very powerful feature by itself, specially the fact that wrappers do not need to be written for this to work.



    ... now, if I could only make the CLIPS.DLL to play nicely...



    Papo
    #14
    Anything else we might add? /
    November 14, 2005, 06:56:17 AM
    Quote from: "pjot"Hm, ok. But then I don't see the use of the 'case' statement. It can be withdrawn from newLisp completely, since all selections can be peformed with 'if' just as easy.


    Well, there might be a case for "case" if there is less overhead than "if" or "cond".



    Papo
    #15
    newLISP and the O.S. / New Lisp, Com? How
    October 25, 2005, 02:41:32 PM
    Hi:



    Even though NewLisp can load DLL's using the import function, is there any way to access COM components from newLisp?  Probably this would solve some of the short comings like like of ODBC by using Jet and to be able to access Office from newLisp.



    Regards,



    Papo