%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% private define assoc_has_default_value(hash, defaultvalref) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% { variable min_char = 32; % ' ' variable max_char = 126; % '~' % find a string that is no key of hash variable N = 0; variable key = ""; while(assoc_key_exists(hash, key)) { N++; variable a = UChar_Type[N]; a[*] = min_char; key = ""; loop(N) key += char(min_char); while(assoc_key_exists(hash, key)) { variable i = -1; do i++, a[i] = min_char+((a[i]-min_char+1) mod (max_char-min_char+1)); while(a[i]==min_char && i0); % qualifier_exists("fold"); indent++; switch(type) { case String_Type or case BString_Type: sprintf("\"%S\"%s", val, (type==BString_Type ? "B" : "")); % left on stack } { case Array_Type or case List_Type: (type==Array_Type ? "[" : "{") + sprintf(" %% %S", val) + (fold ? " %{{{" : "") + "\n"; % left on stack last = length(val)-1; _for i (0, last, 1) () + sp+" " + datatype_to_string(val[i]; indent=indent) + (i 'Folding' => 'Enable Folding') % for nested data structures, which can hence be % very easily investigated. % % The S-Lang code for x can be modified. After % saving the temporary file and closing the editor, % the file is evaluated, which should return an % S-Lang object that is either stored in x % (if passed by reference) or returned. %!%- { variable is_ref = (typeof(x)==Ref_Type); variable xx = ( is_ref ? @x : x ); variable t = typeof(xx); variable tmpfile = qualifier("tmpfile", sprintf("/tmp/edit_var_%d_%d", getuid(), getpid())); variable fp = fopen(tmpfile, "w"); ()=fputs("% -*- mode: SLang; mode: fold -*-\n\n" +(t==List_Type ? "($0=" : "") +datatype_to_string(xx) +(t==List_Type ? ", $0)" : ""), fp); ()=fclose(fp); variable e = getenv("EDITOR"); if(e==NULL) e = "jed"; if(system(e+" "+tmpfile)) if(is_ref) return; else return x; try(e) ()=evalfile(tmpfile); % S-Lang code produces return value that is left on stack catch AnyError: { vmessage("\"%s\" exception:\n%s\n%s:%d", e.descr, e.message, e.file, e.line); if(is_ref) return; else return NULL; } finally ()=remove(tmpfile); if(is_ref) @x = (); }