@@ -95,9 +95,8 @@ class Tuple {
9595function Primitive ( v ) { return new Tuple ( new V ( "<primitive>" ) , new Env ( [ [ "<primitive>" , function * ( ) { while ( true ) yield v ; } ( ) ] ] ) ) ; }
9696
9797const primitives = new Env ;
98- primitives . setThunk ( "trace" , new Tuple ( Primitive ( function ( v ) { console . log ( String ( v . term ) ) ; return v ; } ) , new Env ) ) ;
99-
100- const Y = new L ( "f" , new A ( new L ( "x" , new A ( new V ( "f" ) , new A ( new V ( "x" ) , new V ( "x" ) ) ) ) , new L ( "x" , new A ( new V ( "f" ) , new A ( new V ( "x" ) , new V ( "x" ) ) ) ) ) ) ;
98+ primitives . setThunk ( "trace" , new Tuple ( Primitive ( function ( v ) { console . info ( String ( v . term ) ) ; return v ; } ) , new Env ) ) ;
99+ primitives . setThunk ( "Y" , new Tuple ( new L ( "f" , new A ( new L ( "x" , new A ( new V ( "f" ) , new A ( new V ( "x" ) , new V ( "x" ) ) ) ) , new L ( "x" , new A ( new V ( "f" ) , new A ( new V ( "x" ) , new V ( "x" ) ) ) ) ) ) , new Env ) ) ;
101100
102101function fromInt ( n ) { return fromIntWith ( ) ( n ) ; }
103102
@@ -176,6 +175,7 @@ function parseWith(cfg={}) {
176175 if ( purity === "Let" )
177176 return Array . from ( FV ) . reduce ( ( tm , nm ) => {
178177 if ( env . has ( nm ) ) {
178+ if ( config . verbosity >= "Verbose" ) console . debug ( ` using ${ nm } = ${ env . getValue ( nm ) } ` ) ;
179179 tm . env . set ( nm , env . get ( nm ) ) ;
180180 return tm ;
181181 } else {
@@ -185,16 +185,17 @@ function parseWith(cfg={}) {
185185 } , new Tuple ( term , new Env ) ) ;
186186 else if ( purity === "LetRec" )
187187 return Array . from ( FV ) . reduce ( ( tm , nm ) => {
188- if ( nm === name )
189- return tm ;
190- else if ( env . has ( nm ) ) {
191- tm . env . set ( nm , env . get ( nm ) ) ;
192- return tm ;
193- } else {
194- if ( verbosity >= "Concise" ) console . error ( `parse: while defining ${ name } = ${ term } ` ) ;
195- throw new ReferenceError ( `undefined free variable ${ nm } ` ) ;
196- }
197- } , new Tuple ( FV . has ( name ) ? new A ( Y , new L ( name , term ) ) : term , new Env ) ) ;
188+ if ( nm === name )
189+ return tm ;
190+ else if ( env . has ( nm ) ) {
191+ if ( config . verbosity >= "Verbose" ) console . debug ( ` using ${ nm } = ${ env . getValue ( nm ) } ` ) ;
192+ tm . env . set ( nm , env . get ( nm ) ) ;
193+ return tm ;
194+ } else {
195+ if ( verbosity >= "Concise" ) console . error ( `parse: while defining ${ name } = ${ term } ` ) ;
196+ throw new ReferenceError ( `undefined free variable ${ nm } ` ) ;
197+ }
198+ } , new Tuple ( FV . has ( name ) ? new A ( env . getValue ( "Y" ) , new L ( name , term ) ) : term , new Env ) ) ;
198199 else if ( purity === "PureLC" )
199200 if ( FV . size ) {
200201 if ( verbosity >= "Concise" ) console . error ( `parse: while defining ${ name } = ${ term } ` ) ;
@@ -300,6 +301,10 @@ function parseWith(cfg={}) {
300301 const [ i , r ] = defn ( 0 ) ;
301302 if ( i === code . length ) {
302303 const [ name , term ] = r ;
304+ if ( name == "Y" )
305+ console . warn ( "<span style=\"color:orange\">redefining Y is NOT RECOMMENDED and you do so at your peril</span>" ) ;
306+ if ( config . verbosity >= "Loquacious" )
307+ console . debug ( `compiled ${ name } ${ config . verbosity >= "Verbose" ? ` = ${ term } ` : "" } ` ) ;
303308 return env . setThunk ( name , wrap ( name , term ) ) ;
304309 } else
305310 error ( i , "defn: incomplete parse" ) ;
0 commit comments