beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
ampersanda 2020-11-22T02:24:00.251800Z

Hey guys, when I was doing my project (lein + figwheel-main) converting videos to gif i have a problem after building it into production code, which has an error

Uncaught TypeError: Yo.Zc is not a function
    at t.<anonymous> (main_bundle.js:6)
    at t.componentDidMount (main_bundle.js:6)
    at lo (main_bundle.js:22)
    at da (main_bundle.js:22)
    at t.unstable_runWithPriority (main_bundle.js:30)
    at Bl (main_bundle.js:22)
    at ha (main_bundle.js:22)
    at Zo (main_bundle.js:22)
    at Qo (main_bundle.js:22)
    at Ma (main_bundle.js:22)
I guess it's because of the ffmpeg 's functions were also minified, so I had this keyword called externs , but I don't know how to do it. Do you guys have any good references to do that? Thank you

ampersanda 2020-11-22T02:24:40.251900Z

I used the code like this

(ns ^:figwheel-hooks video-to-gif.core
  (:require
    ["@ffmpeg/ffmpeg" :refer [createFFmpeg fetchFile]]))
and it's installed using npm install

2020-11-22T05:34:27.252200Z

Hey guys, im getting an error I dont know how to solve. WARNING: contains? already refers to: #'clojure.core/contains? in namespace: clojure-calendar.core, being replaced by: #'java-time/contains? WARNING: iterate already refers to: #'clojure.core/iterate in namespace: clojure-calendar.core, being replaced by: #'java-time/iterate WARNING: range already refers to: #'clojure.core/range in namespace: clojure-calendar.core, being replaced by: #'java-time/range WARNING: min already refers to: #'clojure.core/min in namespace: clojure-calendar.core, being replaced by: #'java-time/min WARNING: format already refers to: #'clojure.core/format in namespace: clojure-calendar.core, being replaced by: #'java-time/format WARNING: zero? already refers to: #'clojure.core/zero? in namespace: clojure-calendar.core, being replaced by: #'java-time/zero? WARNING: max already refers to: #'clojure.core/max in namespace: clojure-calendar.core, being replaced by: #'java-time/max (ns clojure-calendar.core (:gen-class) (:require [cheshire.core :refer :all])) (refer-clojure :exclude [range iterate format max min]) (use 'java-time) Im guessing the solution is in one of the five lines above. Ive tried a couple thing wihtout success. Thanks in advance.

practicalli-john 2020-11-23T14:04:20.269300Z

Your require expression is over-writing one of the functions from clojure core. These errors are one example of why :refer :all and use are not recommended and can cause lots of debugging. If a namespace is predominantly about using a specific library, then

(:require [cheshire.core :refer [function-name another-function etc])
A classic example is a test namespace that uses clojure core
(ns practicalli.random-function-test
  (:require [clojure.test :refer [deftest is testing]]
            [practicalli.random-function :as sut]))
Otherwise use a meaningful alias, ideally refering to what that library is doing (which makes it easer to swap out with a different library later on if required). As Cheshire is a JSON related library, then
(ns my.ns
  (:require [cheshire.core :as json]))
This gives a context to all the functions called from that library and makes code easier for humans to understand.

🎉 1
2020-11-23T19:14:41.272800Z

the literal answer here is that contains? is missing from the refer-clojure additions

2020-11-23T19:15:03.273Z

but yeah, refer all and use are not typically used

2020-11-24T05:18:47.321Z

(ns clojure-calendar.core (:gen-class) (:refer-clojure :exclude [range iterate format max min]) (:require [cheshire.core :refer :all] [java-time :refer [local-date plus days]])) Heres what I went with. This gave me no errors when booting and when running the application

practicalli-john 2020-11-24T06:04:02.321600Z

Personally I really don't like this code. It seems I've failed to convey why. My apology.

2020-11-24T14:41:10.327700Z

What would you recommend?

2020-11-24T16:39:58.335100Z

the normal thing is to never invoke :refer :all and to instead use :as to give the namespace an alias

2020-11-24T16:41:00.335700Z

with :refer we'd only grab functions that are used very frequently through the namespace

2020-11-22T06:11:51.252500Z

The line (use 'java-time) is likely the cause of this. use means that you want all names defined in the specified namespace to NOT require any prefix in order to refer to them in the namespace clojure-calendar.core, where the use occurs. Some of those names apparently are the same as names in clojure.core

2020-11-22T06:13:45.252700Z

If you are willing to use a prefix for the names in the java-time namespace, you can instead do something like this:

(ns clojure-calendar.core
  (:gen-class)
  (:require [cheshire.core :refer :all]
            [java-time :as jt]))

;; Use jt/zero? to refer to the name zero? inside of the namespace
;; java-time, and zero? to refer to the name zero? in clojure.core

2020-11-22T06:17:11.252900Z

If you truly want to use no prefix for the names in namespace java-time, and you are OK with using clojure.core/zero? if you want to use the definition of zero? in clojure.core, then you could use something like this:

(ns clojure-calendar.core
  (:gen-class)
  (:refer-clojure :exclude [range iterate format max min])
  (:require [cheshire.core :refer :all]
            [java-time :refer :all]))

2020-11-22T06:19:15.253100Z

It isn't clear to me why having the code the way you show it is not avoiding these warning messages. They are harmless, but agreed it is good to try to eliminate them, so you do not get used to ignoring warnings.

2020-11-22T06:45:26.253500Z

I tried both solutions. I went with the second solution as I didnt have to change or put jt infront of things. It eliminated most errors. Im still getting these WARNING: contains? already refers to: #'clojure.core/contains? in namespace: clojure-calendar.core, being replaced by: #'java-time/contains? WARNING: zero? already refers to: #'clojure.core/zero? in namespace: clojure-calendar.core, being replaced by: #'java-time/zero? If you think taking a peep at the project will help. https://github.com/SantoHerrera/clojureCalendar

2020-11-22T06:45:33.253800Z

Thanks for the help

st3fan 2020-11-22T13:03:52.254700Z

I wrote a test for a macro by comparing the macroexpand result to what i expect - does that make sense?

2020-11-22T15:12:40.254800Z

I think it is a kind of test that is direct and can certainly make sense. Another is to write a test that invokes the macro and tests the behavior of executing the resulting code, of course.

st3fan 2020-11-22T15:39:13.255Z

Yeah that one is more tricky - it create a var in the current namespace, so I will have to understand how that works in tesring. But I will give it a shot.

st3fan 2020-11-22T15:40:38.256400Z

Hmm interesting problem .. I have a macro that calls out to app.util/foo - when running in production this works because app.util is loaded .. but when I run a unit test, app.util is not loaded yet and compilation fails.

st3fan 2020-11-22T15:41:12.257Z

I can solve this by requiring app.util in my test of course. But, I wonder if that is the correct solution.

st3fan 2020-11-22T15:42:16.257500Z

What do you do with macros that need to refer to code in different packages. Should the macro somehow load those, or should that be part of the package where the macro is called?

Dave Russell 2020-11-22T18:37:58.262200Z

Hey folks! Is there a generic way in Clojure to implement something like the multi-method table, where you can retrieve all defmethod definitions using methods? E.g. suppose I write a library with a deffoobar macro -- I'd like a feature of this library to be that it pulls in all the user's deffoobar definitions and does something to them

2020-11-22T19:11:12.262300Z

If you mean, is there some provided functions or data structures and conventions that extensions like that are encouraged to use, then I believe the answer is "no".

2020-11-22T19:11:38.262500Z

You can of course examine the existing implementation of those things, and implement something similar yourself.

2020-11-22T19:14:29.262700Z

I may be misunderstanding your original message, but I thought that methods lets you get all method definitions for a single multimethod that you provide as a parameter. I do not believe anything in Clojure lets you retrieve all names given in defmulti invocations, for example.

2020-11-22T19:15:01.262900Z

But you did say all defmethod definitions, not defmulti definitions, so that is likely what you intended.

Dave Russell 2020-11-22T19:51:10.263100Z

Ah good to know, I'll look into implementing something myself but it's great to have clarification :)

Dave Russell 2020-11-22T19:54:13.263300Z

And yes - the mechanism by which methods retrieves definitions for a single multimethod is all I'm after, so your original interpretation was spot on

Dave Russell 2020-11-22T19:54:17.263500Z

Appreciate the help!