Skip to content

Macros Can't find any functions on the REPL or try-wisp #124

Description

@vshesh

A lot of macros will fail to be accepted on the repl command line.
I give this ns first (so you know everything has been imported)

(ns dev
  (:require
     ; normal runtime comparison and creation functions...
     [wisp.runtime :refer [identity odd? even?
                           dictionary keys vals key-values merge map-dictionary
                           satisfies? contains-vector?
                           nil? true? false? string? number?
                           dictionary? date? boolean? error? re-pattern? object?
                           re-find re-matches re-pattern
                           inc dec str char int subs
                           == > >= < <= + - / *
                           and or print]]

     ; seq abstractions common to most functional languages
     [wisp.sequence :refer [lazy-seq  seq  list  vec  cons  conj
                            lazy-seq? seq? list? sequential? empty?
                            reverse map filter reduce count
                            first second third nth rest last butlast
                            take take-while drop assoc concat
                            repeat every? some
                            partition interleave sort]]

     ;; string functions:
     ;; split split-lines join
     ;; upper-case lower-case capitalize pattern-escape
     ;; replace-first replace blank? reverse
     [wisp.string :as s]))

And then I try something like:

=> (defn tack-on [tack coll] (map (fn [x] [x tack]) coll))
; everything is good here - the function works as expected
=> (defmacro tackmacro [vecs] (tack-on "=" vecs))
=> (tackmacro [1 2 3])
ReferenceError: tackOn is not defined
    at tackmacro (eval at <anonymous> (/Users/Vishesh/repos/dng3/node_modules/wisp/backend/escodegen/generator.js:126:32), <anonymous>:3:9)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:72:36
    at expand (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:74:7)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:176:33
    at macroexpand1 (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:177:11)
    at loop (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:183:30)
    at macroexpand (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:188:11)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:597:31
    at analyzeList (/Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:601:11)
    at analyze (/Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:663:160)

Which looks like there's something else going on here with the way regular functions and macros interact - it seems like they're not finding each other?

I can replicate this with a much simpler example:

=> (defn test [x] (+ 1 x))
=> (defmacro testm [x] (test x))
=> (testm 1)
ReferenceError: test is not defined
    at testm (eval at <anonymous> (/Users/Vishesh/repos/dng3/node_modules/wisp/backend/escodegen/generator.js:126:32), <anonymous>:3:9)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:72:36
    at expand (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:74:7)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:176:33
    at macroexpand1 (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:177:11)
    at loop (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:183:30)
    at macroexpand (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:188:11)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:597:31
    at analyzeList (/Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:601:11)
    at analyze (/Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:663:160)
=> 

It's even replicable with the base functions

=> (defmacro component [m] (assoc m :restrict :EA))
=> (component {})
ReferenceError: assoc is not defined
    at component (eval at <anonymous> (/Users/Vishesh/repos/dng3/node_modules/wisp/backend/escodegen/generator.js:126:32), <anonymous>:3:9)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:72:36
    at expand (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:74:7)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:176:33
    at macroexpand1 (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:177:11)
    at loop (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:183:30)
    at macroexpand (/Users/Vishesh/repos/dng3/node_modules/wisp/expander.js:188:11)
    at /Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:597:31
    at analyzeList (/Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:601:11)
    at analyze (/Users/Vishesh/repos/dng3/node_modules/wisp/analyzer.js:663:160)
=> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions