@@ -59,7 +59,6 @@ internals.forcemv = function(x) {
5959 return typeof x == 'object' && x !== null && 'multiple-value' in x ? x : internals . mv ( x ) ;
6060} ;
6161
62-
6362//
6463// Workaround the problems with `new` for arbitrary number of
6564// arguments. Some primitive constructors (like Date) differ if they
@@ -331,15 +330,21 @@ packages.KEYWORD = {
331330
332331jscl . CL = packages . CL . exports ;
333332
334- internals . unboundFunction = function ( ) {
335- throw new Error ( "Function '" + this . name + "' undefined" ) ;
333+
334+
335+ const UNBOUND = Symbol ( 'UnboundFunction' )
336+
337+ internals . makeUnboundFunction = function ( symbol ) {
338+ const fn = ( ) => { throw new Error ( "Function '" + symbol . name + "' undefined" ) ; }
339+ fn [ UNBOUND ] = true ;
340+ return fn ;
336341} ;
337342
338343internals . Symbol = function ( name , package_name ) {
339344 this . name = name ;
340345 this . package = package_name ;
341346 this . value = undefined ;
342- this . fvalue = internals . unboundFunction ;
347+ this . fvalue = internals . makeUnboundFunction ( this )
343348 this . stack = [ ] ;
344349} ;
345350
@@ -352,9 +357,17 @@ internals.symbolValue = function (symbol){
352357 }
353358} ;
354359
360+ internals . fboundp = function ( symbol ) {
361+ if ( symbol instanceof internals . Symbol ) {
362+ return ! symbol . fvalue [ UNBOUND ]
363+ } else {
364+ throw new Error ( `${ symbol } is not a symbol` )
365+ }
366+ }
367+
355368internals . symbolFunction = function ( symbol ) {
356369 var fn = symbol . fvalue ;
357- if ( fn === internals . unboundFunction )
370+ if ( fn [ UNBOUND ] )
358371 symbol . fvalue ( ) ;
359372 return fn ;
360373} ;
0 commit comments