defmacro not defined in ClojureScript? - clojurescript

I'm trying to use defmacro in ClojureScript, but I'm getting a console error:
TypeError: 'undefined' is not an object (evaluating 'crd.core.defmacro.call')
Here's the test code that's generating the error:
(ns crd.core)
(defmacro t [] `())
And the generated JavaScript code:
goog.provide('crd.core');
goog.require('cljs.core');
crd.core.defmacro.call(null,crd.core.t,cljs.core.Vector.fromArray([]),null);
Any pointers on what I'm doing wrong?

My failure: I didn't read Differences from Clojure. ClojureScript does support macros, but only in .clj files that are imported with require-macros.

Related

How can I stop the ClojureScript compiler from resolving certain `require`s?

In my ClojureScript code I am requiring a JavaScript module called seedrandom which is in the node_modules folder, like this:
(ns something.core
(:require ["seedrandom" :as rnd]))
(js/console.log (.quick (rnd "x")))
According to the seedrandom documentation it is intended for both nodejs and the browser, and I've previously included and used it successfully in ClojureScript code via a <script> tag, confirming it works in the browser.
Running this cljs file in lumo on the command line works well and outputs a deterministically random number.
When I try to use this same cljs file in my Reagent frontend project I see the following error:
Compiling build :app to "public/js/app.js" from ["src" "env/dev/cljs"]...
events.js:183
throw er; // Unhandled 'error' event
^
Error: module not found: "crypto" from file /home/chrism/dev/something/node_modules/seedrandom/seedrandom.js
at onresolve (/home/chrism/dev/something/node_modules/#cljs-oss/module-deps/index.js:181:30)
...
Inside seedrandom.js we see the following:
// When in node.js, try using crypto package for autoseeding.
try {
nodecrypto = require('crypto');
} catch (ex) {}
Clearly this code is intended to ignore the built-in nodejs crypto module when running in the browser. The problem, as far as I can tell, is that the ClojureScript compiler does not know that - it sees that require('crypto') and tries to pull it into the compilation phase, but can't find it because it's a nodejs built-in.
Is there some way I can tell the compiler to ignore that particular require? Or can I shim the 'crypto' module somehow? What is the cleanest way to solve this?
Note: I have previously experienced this same issue with JavaScript modules which check for the fs node module. Hope we can find a general solution to use again in future. Thanks!
Relevant versions: [org.clojure/clojurescript "1.10.520"] and [reagent "0.8.1"].
This answer is related, asking a similar question from the perspective of Google Closure, which ClojureScript uses, but I'm looking for an answer I can use specifically with cljs.

Why is eval not bound in REPL?

I'm learning clojure, I'm trying to experiment in the clojure REPL using shadow-cljs. I thought eval was part of the clojure.core, but using this
(eval (list + 1 2))
produces Error: cljs.core/*eval* not bound
I also tried this but got the same error
(require `clojure.core)
(clojure.core/eval (list + 1 2))
Why is this?
You are likely using a ClojureScript REPL where eval only works as part of self-hosted builds which require additional setup. clojure.core is automatically aliased to cljs.core as part of the compiler, that is why you get the cljs.core/*eval* error.
If you intend to do actual Clojure REPL work you should use
shadow-cljs clj-repl
which will give you a pure Clojure REPL.

VS2017 - Error overloading function with different template template parameters with same argument

Error overloading function with different template template parameters with same argument
In VS2017 I am getting an error
error C2535: 'bool
However, the two function declarations clearly have different arguments.
This code compiles fine on GCC.
I found a similar error here:
Error overloading function with different template template parameters with same argument
Could anybody suggest a solution as I want to code to be the same for linux and windows and compile with both GCC and MSVC.

Ionic App throwing "Cannot read property 'id' of null at PinchRecognizer.recognizeWith" loading Forge Viewer

I am working on an app written in TypeScript using the Ionic Framework. I'm attempting to load the first model into the forge viewer and I receive the below error when I attempt to call the viewer start method:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'id' of null
TypeError: Cannot read property 'id' of null
at PinchRecognizer.recognizeWith (viewer3D.js?v=4.0:2326)
at Array.forEach (<anonymous>)
at each (viewer3D.js?v=4.0:945)
at invokeArrayArg (viewer3D.js?v=4.0:925)
at PinchRecognizer.recognizeWith (viewer3D.js?v=4.0:2320)
at new Autodesk.Viewing.GestureHandler (viewer3D.js?v=4.0:13760)
at GuiViewer3D.Viewer3D.createControls (viewer3D.js?v=4.0:44610)
at GuiViewer3D.Viewer3D.initialize (viewer3D.js?v=4.0:44694)
at GuiViewer3D.initialize (viewer3D.js?v=4.0:50771)
at GuiViewer3D.Viewer3D.start (viewer3D.js?v=4.0:44438)
at PinchRecognizer.recognizeWith (viewer3D.js?v=4.0:2326)
at Array.forEach (<anonymous>)
at each (viewer3D.js?v=4.0:945)
at invokeArrayArg (viewer3D.js?v=4.0:925)
at PinchRecognizer.recognizeWith (viewer3D.js?v=4.0:2320)
at new Autodesk.Viewing.GestureHandler (viewer3D.js?v=4.0:13760)
at GuiViewer3D.Viewer3D.createControls (viewer3D.js?v=4.0:44610)
at GuiViewer3D.Viewer3D.initialize (viewer3D.js?v=4.0:44694)
at GuiViewer3D.initialize (viewer3D.js?v=4.0:50771)
at GuiViewer3D.Viewer3D.start (viewer3D.js?v=4.0:44438)
at c (polyfills.js:3)
at c (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4620)
at t.invokeTask (polyfills.js:3)
at r.runTask (polyfills.js:3)
at o (polyfills.js:3)
at e.invokeTask [as invoke] (polyfills.js:3)
at p (polyfills.js:2)
I read another stack overflow with the same issue, where there were competing libraries but I do not think that is the case for me. (Unless Ionic is utilizing something.)
Any ideas on what could be missing?
Here is the feedback I received a while ago from a developer having the same exception than you on Cordova:
I managed to find the cause of the console error. In hammer.js (which
is included in the viewer3D.js file), there is a method on the
‘Manager’ object called ‘get(Recognizer)’ which contains a check
whether the provided parameter object is of type ‘Recognizer’. This
check somehow fails, causing the method to return null. This will
break the gesture handler later on in the call stack. I managed to fix
it in my environment by changing the check to check the object for
type ‘Object’ rather than ‘Recognizer’. This seems to fix my issue,
and does not seem to break other functionality. I couldn’t find
anything unusual on the Forge side that could have caused this issue
though, so it could be a generic problem.
Unfortunately I think you will have to use a custom modified version of the viewer3D.js source and patch the source yourself.

mxGetProperty function in octave

I'm trying to adopt some C-coded matlab module to octave. mkoctave returns batch of warning, but no errors and generates mex file. However octave cannot load this file and returns an error:
error: JustKmodel.m: /home/simulations/exampls/RetinalMap-master/stepFastGlobal.mex:
failed to load: /home/simulations/exampls/RetinalMap-master/stepFastGlobal.mex: undefined symbol: mxGetProperty
As far as I can understand there is no such function GetProperty or library isn't available.
I'll appreciate any ideas how to work around this problem