Skip to content

Instantly share code, notes, and snippets.

@aw
Created February 3, 2018 13:41
Show Gist options
  • Select an option

  • Save aw/23e5a33d1254a40b80b2c1fc94af5f47 to your computer and use it in GitHub Desktop.

Select an option

Save aw/23e5a33d1254a40b80b2c1fc94af5f47 to your computer and use it in GitHub Desktop.

Revisions

  1. aw created this gist Feb 3, 2018.
    29 changes: 29 additions & 0 deletions picolisp-wildcard.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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:

    ```bash
    grep -l "let" *
    ```

    ### 1. with (cons)

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

    ```picolisp
    (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`

    ```picolisp
    (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.