wryun / es-shell

es: a shell with higher-order functions
http://wryun.github.io/es-shell/
Other
307 stars 25 forks source link

core dump on self-referential closure #4

Open wryun opened 12 years ago

wryun commented 12 years ago

https://wryun.github.io/es-shell/mail-archive/msg00987.html

This dumps core:

; echo <={@ x{x=@{$*}; $&result $x}}

why? check this one first:

; echo <={@ x{$&result @{$}} X} %closure(x=X)@ * {$}

Now, imagine replacing X by the entire closure, and you have a closure containing a reference to itself. That can never be printed, of course.

memreflect commented 1 month ago

This issue is caused solely by attempting to print an automatically created closure that somehow refers to itself. If you avoid trying to display the result, you can pass the resulting lambda around, invoke it with arguments, etc.

The other part of the reason is the fact that some code in conv.c was commented out with #if 0 that handled exactly this case, but the output can be quite noisy as you will see below.

; whatis <={
    @ x a y {
      (a x y) = 0 @{a = $*} {echo $a}
      $&result $x $y
    }
  }
%closure(x='0 $&nestedbinding';a=0;y='%closure(x=''1 $&nestedbinding'';a=0;y=''0 $&nestedbinding'')@ * {echo $x}')@ * {a = $*}
%closure(x='%closure(x=''0 $&nestedbinding'';a=0;y=''1 $&nestedbinding'')@ * {echo $y}';a=0;y='0 $&nestedbinding'){echo $a}

I have suggested abridging of closures in #103, but dropping the #if 0 and corresponding #endif in conv.c will allow you to obtain output like the above, resolving this issue.