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

#1
Whither newLISP? / Tail call optimization
June 22, 2011, 07:14:56 AM
I have done some search in the forum but yet I haven't found the answer for a just-out-of-curiosity question: Does newLISP do tail call optimization?
#2
Anything else we might add? / Documentation Fix
May 30, 2011, 02:01:53 AM
I discovered some small errors on the page "http://www.newlisp.org/index.cgi?page=Differences_to_Other_LISPs">Differences to Other LISPs"[1], a couple of lines before section "Implicit Indexing":



"readong/translation" should be "reading/translating"

"This wayte h overhead" should be "This way, the overhead"



Please fix them.



[1]: http://www.newlisp.org/index.cgi?page=Differences_to_Other_LISPs">//http://www.newlisp.org/index.cgi?page=Differences_to_Other_LISPs
#3
newLISP and the O.S. / Colors in Terminal
May 29, 2011, 08:41:05 AM
Hi guys,



I'm developing a console application which makes use of VT-100 compatible terminals.  Usually, to produce text color, I use the escaped phrase `\033$COLOR_CODE`.  For example, to output the world "Hello world" in red, I use



echo "\033[41mHello world!"


In newLISP, I tried to do the same thing with



(println "\\033[41mHello world!")
(println {\033[41mHello world!})


But neither works. Does anyone know how to produce colors in terminal with newLISP?
#4
Hi newLISPers,



I have a question about memory management when loading shared library.  In C/C++, after finishing using a library, one needs to unload it to ensure that:



[*] memory is properly deallocated, and
  • [*] the system could do some clean-up, like closing file handlers, ...
  • [/list]


    In newLISP, should/must we use the same method? If yes, then how to do it properly.  Let's take the example in newLISP Code Patterns:



    We have this C program:



    /* compile with:
     *     $ gcc <filename> -fPIC -shared -o <libname>
     * or
     *     $ tcc <filename> -shared -o <libname>
     **/

    #include <string.h>
    #include <stdlib.h>

    typedef struct mystruc
    {
        int number;
        char *ptr;
    } MyStruc;

    MyStruc *foo3(char *ptr, int num)
    {
        MyStruc *astruc;
        astruc = malloc( sizeof( MyStruc ) );
        astruc->ptr = malloc( len( ptr ) + 1 );
        strcpy( astruc->ptr, ptr );
        astruc->number = num;
        return astruc;
    }


    After compiling it to a shared library, we can import ``MyStruc`` to our newLISP program by using:



    (import "mystruc.so" "foo3")
    (setq 'astruc (foo3 "hello world" 123))
    (get-string (get-integer (+ a struc 4))) ;; 4 = sizeof int in C
    (get-integer astruc)


    Do we have to manually deallocate memory allocated to ``astruc``?  According to what I understand, since ``astruc`` is created by newLISP, exists in newLISP environment, newLISP's garbage collector automatically takes care of memory management for us.  Right?