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

#1
Well the bug is not here, but why I can't use variable as the first parameter?



(set 'y 2015)



(date-value y 7 18)



ERR: missing argument in function date-value.
#2
newLISP in the real world / 10.6.3 date-value bug
July 18, 2015, 07:22:43 AM
The year parameter never get evalueated.



params = getIntegerExt(params, (UINT *)&year, FALSE);



change FALSE to evalFlag please.
#3
context is value, so we can use (uuid) to generate unique symbol in MAIN, then make it a context. But there's no gc, you have to delete the context yourself.





(set 'a (new Tree (sym (string "_" (uuid)) MAIN)))





delete the context like this



(set 'name (sym (term a) MAIN)) ; find the context's name in MAIN

(delete name) ; delete the context

(delete name) ; delete the symbol in MAIN
#4
(define types '("nil" "true" "int" "float" "string" "symbol" "context"
    "primitive" "import" "ffi" "quote" "expression" "lambda" "fexpr" "array"
    "dyn_symbol"))

(define (typeof v)
    (types (& 0xf ((dump v) 1))))


the types defined in newlisp.h
#5
i < cell->aux - 1



raise error like regexError("Unknown option at", i, buffer);
#6
Fogot regex-comp member, others look nice.



Debug should be easier if carp for other characters, maybe throw No.39 regular expression error.
#7
Hello, I write a function to support string as regex-options.



Example use "ip" to replce (| 0x10000 1), {u} than 2048


CELL* parseRegexOptions(CELL* params, UINT * options, int evalFlag)
{
    CELL* cell;
    int i;
    char* buffer;

    if (evalFlag)
        cell = evaluateExpression(params);
    else
        cell = params;

    *options = 0;

    if (cell->type == CELL_STRING) {
        buffer = (char*)cell->contents;
        for (i = 0; i < cell->aux; i ++) {
            switch (buffer[i]) {
                    case 'i': *options |= 1; break;         /* PCRE_CASELESS  */
                    case 'm': *options |= 2; break;         /* PCRE_MULTILINE */
                    case 's': *options |= 4; break;         /* PCRE_DOTALL    */
                    case 'x': *options |= 8; break;         /* PCRE_EXTENDED  */
                    case 'u': *options |= 2048; break;      /* PCRE_UTF8      */
                    case 'p': *options |= 0x10000; break;   /* PRECOMPILED    */
            }
        }
    } else {
        getIntegerExt(cell, options, FALSE);
    }

    return (params->next);
}


First add CELL * parseRegexOptions(CELL * param, UINT * options, int evalFlag); to proto.h



For parse regex replace directory member find-all starts-with ends-with just change getInteger(..., &options) / getIntegerExt(..., &options, FALSE) to parseRegexOptions



search and find check options's type, we need one more step. Change

isNumber(params->type)

to

(isNumber(params->type) || params->type == CELL_STRING)



At last find has two syntax so two place to change.





It's useful for people come from PCRE world. And someone asked this feature months ago.
#8
(set 'A:A (array 10))

(length A)     --> 0



In order to pass big array by reference transparently, 'length' should return the array's size.
#9
stat return -1 for string like "d:". But in isFile isDirectory "d:/" is changed to "d:" before transfer to stat, we should check before temporary replace last  or / to NUL.



maybe change



if (slash == '\' || slash == '/')

    *(fileName + len - 1) = 0;



to



if ((slash == '\' || slash == '/') && (! (len >= 2 && *(fileName + len - 2) == ':')))

    *(fileName + len -1) = 0;