SquircleSpace / shcl

SHell in Common Lisp
Apache License 2.0
318 stars 17 forks source link

Simple custom builtin failing with stack exhausted error. #5

Closed ralt closed 6 years ago

ralt commented 6 years ago

I wanted to write a simple alias like alias ls=ls --color, so I wrote a simple builtin to start off:

(define-builtin ls (&rest args)
  (shcl/core/lisp-interpolation:evaluate-constant-shell-string "ls --color"))

This fails quite spectularly:

ralt@zap:~/common-lisp/shcl$ ls
INFO: Control stack guard page unprotected
Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread
#<THREAD "main thread" RUNNING {1002DD8083}>:
  Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

PROCEED WITH CAUTION.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [IGNORE] IGNORE
  1: [DIE   ] SHCL/SHELL/MAIN::DIE

(SB-KERNEL::CONTROL-STACK-EXHAUSTED-ERROR)
0]

Is that something you're familiar with?

SquircleSpace commented 6 years ago

That's supposed to happen. You defined a recursive function that never bottoms out.

It looks like you're trying to define an alias. I don't have any tests for it or example code to point you at, but SHCL does support aliases. Check out shcl/core/expand:set-alias.

Example:

(shcl/core/expand:set-alias "testAlias" '("ls" "-l"))
#$ testAlias ~ #$

I wrote the alias stuff long before I had good support for builtins. I wonder if I can roll up the concept of an alias into the builtin table, now. Hm.

SquircleSpace commented 6 years ago

https://github.com/bradleyjensen/shcl/issues/6

ralt commented 6 years ago

Oh, duh. Of course.

Thanks!