Skip to content

Instantly share code, notes, and snippets.

@aw
Created February 3, 2018 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aw/23e5a33d1254a40b80b2c1fc94af5f47 to your computer and use it in GitHub Desktop.
Save aw/23e5a33d1254a40b80b2c1fc94af5f47 to your computer and use it in GitHub Desktop.
PicoLisp glob/wildcard expansion in call and exec commands

In PicoLisp, there is often a situation where you want to execute a command with the * argument. Bash shell expands * to the list of filenames, but PicoLisp doesn't.

Here are two workarounds for this bash command:

grep -l "let" *

1. with (cons)

This method prints the results, but you can actually do anything you want with the output (line T)

(in
  (cons 'grep "-l" "let" (dir "."))
  (until  (eof)
          (prinl (line T)) ) )

2. with (apply)

This method simply executes the command and returns the result of the (call): T or NIL

(apply call (dir ".") "grep" "-l" "let")

Note: In both cases, the grep command will only run once. It's not being called once for every file, as in a loop or iteration. In other words, it's efficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment