Skip to content

Commit

Permalink
Abridge closure strings by default
Browse files Browse the repository at this point in the history
A new 'ABRIDGE_CLOSURES' configuration parameter has been added to
esconfig.h.
It defaults to 0 so a closure string is abridged to

	%closure(a;b;...)@ * {...}

When 'ABRIDGE_CLOSURES' is enabled, some old code that was previously
commented out has been uncommented, so even closures with cyclical
references can be printed:

	; whatis <={@ x y { (x y) = @ cmd { $cmd $y } 1 ; result $x }}
	%closure(x='0 $&nestedbinding';y=1)@ cmd{$cmd $y}
	# 0 $&nestedbinding
	#	the code tree associated with the closure, i.e.
	#	'@ cmd{$cmd $y}' in this case
	# {n} $&nestedbinding
	#	the code tree bound to another closure
	#
	# NOTE: $&nestedbinding doesn't actually exist.
	#       It's purely an indicator of a cyclical reference, like
	#	how 'wryun#1=(a b . wryun#1#)' is used in some Lisps to avoid
	#	printing an endless stream of 'a b'.
  • Loading branch information
memreflect committed Aug 3, 2024
1 parent 6a6492a commit 6a36091
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ static void enclose(Format *f, Binding *binding, const char *sep) {
if (binding != NULL) {
Binding *next = binding->next;
enclose(f, next, ";");
#if !ABRIDGE_CLOSURES
fmtprint(f, "%S%s", binding->name, sep);
#else
fmtprint(f, "%S=%#L%s", binding->name, binding->defn, " ", sep);
#endif
}
}

#if 0
#if ABRIDGE_CLOSURES
typedef struct Chain Chain;
struct Chain {
Closure *closure;
Expand All @@ -199,7 +203,7 @@ static Boolean Cconv(Format *f) {
Binding *binding = closure->binding;
Boolean altform = (f->flags & FMT_altform) != 0;

#if 0
#if ABRIDGE_CLOSURES
int i;
Chain me, *cp;
assert(tree->kind == nThunk || tree->kind == nLambda || tree->kind == nPrim);
Expand All @@ -226,7 +230,7 @@ static Boolean Cconv(Format *f) {
fmtprint(f, "%T", tree);
}

#if 0
#if ABRIDGE_CLOSURES
chain = chain->next; /* TODO: exception unwinding? */
#endif
return FALSE;
Expand Down
11 changes: 11 additions & 0 deletions esconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
* line definitions. (That is, remember to do the #ifndef dance.)
*
*
* ABRIDGE_CLOSURES
* if on, produce closure strings without the values bound in a closure:
* %closure(x;y;x)@ * {...}
* else:
* %closure(x=1;y=4;x=9)@ * {...}
* this is particularly useful when dealing with "nested bindings".
*
* ASSERTIONS
* if this is on, asserts will be checked, raising errors on
* actual assertion failure.
Expand Down Expand Up @@ -276,6 +283,10 @@
* default defaults -- don't change this section
*/

#ifndef ABRIDGE_CLOSURES
#define ABRIDGE_CLOSURES 1
#endif

#ifndef ASSERTIONS
#define ASSERTIONS 1
#endif
Expand Down

0 comments on commit 6a36091

Please sign in to comment.