Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(eval `(setq ,(intern (format nil "QUX-~d" b)) b)) is not compilable #318

Open
k-okada opened this issue Aug 17, 2018 · 1 comment
Open

Comments

@k-okada
Copy link
Member

k-okada commented Aug 17, 2018

https://github.com/euslisp/EusLisp/pull/316/files#diff-9bba0365fc242a37a4dc4db56de4973c is not able to compile, (see 5867727)

(setq foo-1 a)
(print foo-1)

(let ((b 2))
  (setq foo-2 b)
  (print foo-2))

(set (intern "BAR-0") 0)
(print bar-0)

(setq a 1)
(set (intern "BAR-1") a)
(print bar-1)

(let ((b 2))
  (set (intern "BAR-2") b)
  (print bar-2))

(set (intern (format nil "BAZ-~d" 0)) 0)
(print baz-0)

(setq a 1)
(set (intern (format nil "BAZ-~d" a)) a)
(print baz-1)

(let ((b 2))
  (set (intern (format nil "BAZ-~d" b)) b)
  (print baz-2))

(eval `(setq ,(intern (format nil "QUX-~d" 0)) 0))
(print qux-0)

(setq a 1)
(eval `(setq ,(intern (format nil "QUX-~d" a)) a))
(print baz-1)

;; NG                                                                                    
(let ((b 2))
  (eval `(setq ,(intern (format nil "QUX-~d" b)) b))
  (print baz-2))

outputs

Call Stack (max depth: 20):
  0: at (setq qux-2 b)
  1: at (load "hoge.so")
  2: at (progn (compiler:compile-file "hoge.l") (load "hoge.so"))
irteusgl: ERROR th=0 unbound variable bb in (setq qux-2 b)E: (exit)
@Affonso-Gui
Copy link
Member

In a minimal example:

(defun foo ()
  (let ((i 10))
    (print i)
    (eval `(print ,i))
    (eval `(print i))))

Is translated as:

static pointer testF1foo(ctx,n,argv,env)
register context *ctx;
register int n; register pointer argv[]; pointer env;
{ register pointer *local=ctx->vsp, w, *fqv=qv;
  numunion nu;
	if (n!=0) maerror();
	local[0]= makeint((eusinteger_t)10L);       // this is our variable i
	local[1]= local[0];
	ctx->vsp=local+2;
	w=(pointer)PRINT(ctx,1,local+1); /*print*/
	local[1]= fqv[0];
	local[2]= local[0];
	ctx->vsp=local+3;
	w=(pointer)LIST(ctx,1,local+2); /*list*/
	ctx->vsp=local+2;
	local[1]= cons(ctx,local[1],w);
	ctx->vsp=local+2;
	w=(pointer)EVAL(ctx,1,local+1); /*eval*/
	local[1]= fqv[0];
	local[2]= fqv[1];                            // references to the symbol i instead of its value
	ctx->vsp=local+3;
	w=(pointer)LIST(ctx,1,local+2); /*list*/
	ctx->vsp=local+2;
	local[1]= cons(ctx,local[1],w);
	ctx->vsp=local+2;
	w=(pointer)EVAL(ctx,1,local+1); /*eval*/    // unbound variable error
	local[0]= w;
testBLK2:
	ctx->vsp=local; return(local[0]);}

As a workaround (eval `(setq ,(intern (format nil "QUX-~d" b)) ,b)) is compilable, but still doesn't fix all the problems in the const.l compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants