Could be a speed record from making a proposal to getting it done... :-)
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
(define (ref-parent r)
(if (null? r) nil (0 -1 r)))
;;
(setq l_nested '("1" "2" "3"
("4" "5" "6"
("7" "8" "9"))
"10" "11" "12"
("13" "14" "15"
("16" "17" "18")))
)
> (l_nested (ref-parent (ref "14" l_nested)))
("13" "14" "15" ("16" "17" "18"))
> (l_nested (ref-parent (ref "11" l_nested)))
ERR: missing argument
> (ref-parent (ref "14" l_nested))
(7)
> (ref-parent (ref "11" l_nested))
()
> (l_nested (ref-parent (ref "11" l_nested)))
("1" "2" "3" ("4" "5" "6" ("7" "8" "9")) "10" "11" "12" ("13" "14" "15" ("16" "17" "18")))
> (ref "not there" l_nested)
nil
> (ref-all "not there" l_nested)
()
Looking at the pointer values passed and assigned and the resultStackIdx, I see that the sequence of assignments is correct. First:Quote from: "Lutz"args = arrayList(args, FALSE)second: *(++resultStackIdx) = args
But incrementing resultStackIdx only works the first time, the second time entering the apply statement, resultStackIdx doesn't increment and is stuck at its old value forever, no matter how often I enter the apply statement. Now the old pointer is overwritten again and again and has never a chance to get processed by popResult() higher up in evaluateExpression() for freeing cells and memory.
So it seems not to be a sequence point problem, but a problem with the ++ operator in gcc but only under certain circumstances.
newlisp.h:#define pushResult(A) (*(++resultStackIdx) = (UINT)(A))
pushResult(args = arrayList(args, FALSE));(*(++resultStackIdx) = (unsigned long)(args = arrayList(args, 0)));Thanks, yes it is definitely a sequence point issue. The following works on all platforms and is the way it is coded now:Quote from: "Lutz"
if(args->type == CELL_ARRAY)
{
args = arrayList(args, FALSE);
pushResult(args);
}
This is the way I had it coded first and tested everywhere. Then changed it to the short form which still worked on my OSX 10.9 Clang based development system. But would break on gcc based distribution compiles and was not tested again :(
Quote from: "hartrock"(*(++resultStackIdx) = (unsigned long)(args = arrayList(args, 0)));
Quote from: "Lutz"
To your question about memory management of the stuff pointed to by args pointer:
...
CELL * p_apply(CELL * params)
{
CELL * expr;
CELL * args;
CELL * cell;
CELL * result;
CELL * func;
ssize_t count, cnt;
UINT * resultIdxSave;
CELL * tmp;
func = evaluateExpression(params);
cell = copyCell(func);
expr = makeCell(CELL_EXPRESSION, (UINT)cell);
params = getEvalDefault(params->next, &args);
if(args->type == CELL_ARRAY) {
/* pushResult(args = arrayList(args, FALSE)); */
/* pushResult((args = (arrayList(args, FALSE)))); */ /* does not work, too */
/* but this is OK */
tmp = arrayList(args, FALSE);
pushResult(args = tmp);
}
;; ...newlisp.h:#define pushResult(A) (*(++resultStackIdx) = (UINT)(A))
(*(++resultStackIdx) = (unsigned long)(args = arrayList(args, 0)));There isQuote from: "Lutz"nocell leak or memory leak :) array-listcreates a new list but it gets popped off from the result stack in evaluateExpression()after the function returns. The cleanupResults()happens only for the results from the individual applyoperations when it had the reduce parameter during the execution of apply. This is necessary to avoid result stack overflow on long lists or arrays. All other minor result stack cleanup is done after function return.
(set 'a (array 10000 (sequence 0 10000)))
;;
(define (til-stats cont divisor)
(let ((tilSize (/ (length cont) divisor))
(tils (array divisor)))
(dotimes
(chunkIx divisor)
(let (off (* chunkIx tilSize))
(++ (tils chunkIx) (apply + (off tilSize cont)))))
tils))
(define (centil-stats cont)
(til-stats cont 10))
;;
(time (centil-stats a) 10000)
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21814 sr 20 0 22260 3308 1144 R 99.4 0.2 2:46.76 newlisp
21815 sr 20 0 26612 7796 1144 R 99.1 0.4 2:45.19 newlisp
CELL * p_apply(CELL * params)
{
CELL * expr;
CELL * args;
CELL * cell;
CELL * result;
CELL * func;
ssize_t count, cnt;
UINT * resultIdxSave;
func = evaluateExpression(params);
cell = copyCell(func);
expr = makeCell(CELL_EXPRESSION, (UINT)cell);
params = getEvalDefault(params->next, &args);
if(args->type == CELL_ARRAY)
pushResult(args = arrayList(args, FALSE));
;;-> here a list will be generated, but ..
if(args->type != CELL_EXPRESSION)
{
if(isNil(args))
{
pushResult(expr);
return(copyCell(evaluateExpression(expr)));
}
else
return(errorProcExt(ERR_LIST_EXPECTED, args));
}
if(params != nilCell)
getInteger(params, (UINT *)&count);
else count = -1;
if(count < 2) count = MAX_LONG;
resultIdxSave = resultStackIdx + 2;
;;-> .. is this taken into account here?
...
Quote from: "TedWalther"
Can you explain your issue a bit better hartrock?
sr@free:~/Ideas/Spiel$ ./gol -h
Usage: gol [options]
-c, --cycles INT num of cycles
-r, --rounds INT num of rounds per cycle
-a, --players-at-all INT players at all
-g, --players-per-game INT players per game
-s, --start-balance INT start balance for each player
-l, --lower-risk-limit FLOAT [opt] 0.0 <= FLOAT <= 1.0 (default: 0.0)
-u, --upper-risk-limit FLOAT [opt] 0.0 <= FLOAT <= 1.0 (default: 1.0)
-d, --distribution-per-cycle FLOAT [opt] 0.0 <= FLOAT <= 1.0 (default: 0.0) fraction of balance to be distributed
-h, --help Print this help message
Quote
Each parameter not starting with a `-', and not a required argument of
a previous option, is a non-option parameter.Each parameter after a
`--' parameter is always interpreted as a non-option parameter.If the
environment variable POSIXLY_CORRECT is set, or if the short option
string started with a `+', all remaining parameters are interpreted as
non-option parameters as soon as the first non-option parameter is
found.
#!/usr/bin/newlisp
(module "getopts.lsp")
(shortopt "a" (println "'a' opt") nil "works as expected")
(shortopt "h" (println (getopts:usage)) nil "usage")
;; Do *not* try this (action won't be triggered):
;; (shortopt "-" (println "'-' opt") nil "stops parsing CLI opts") ; Do *not* try this!
(getopts (2 (main-args)))
(println "After calling getopts.")
(exit)
sr@free:~/NewLisp$ newlisp getopts_bug.lsp -a --
'a' opt
After calling getopts.
sr@free:~/NewLisp$ newlisp getopts_bug.lsp -- -a
After calling getopts.
sr@free:~/NewLisp$
BothQuote from: "Lutz"mapand applyalso take arrays in the next version, but will do array -> list conversion internally to keep code changes / additions to a minimum leveraging existing code.