Fork me on GitHub
#beginners
<
2021-12-29
>
roelof14:12:57

where do I put this on my .edn file

{:npm-deps {"@material-ui/core"  "4.9.13"
            "@material-ui/icons" "4.9.1"}
 ...}
shadow-cljs.edn file :
{:source-paths
 ["src"]

 :dependencies
 [
     [reagent "1.1.0"]
     [re-frame "1.2.0"]
 ]

 :dev-http {8280 "resources/public"}

 :builds
 {:app {:target :browser
        :output-dir "resources/public/js/compiled"
        :asset-path "js/compiled"
        :modules
         {:app {:init-fn toy-project1.core/init}}
         }}}

dvingo15:12:42

I assume that :npm-deps is coming from a library. When you start shadow-cljs it should download those from npm for you.

Arthur17:12:16

npm libraries aren't added to you shadow-cljs.edn file. you should add those to your package.json instead. i'd recommend reading shadow's user guide

roelof10:12:09

I hate it when a tutorial is not right

roelof10:12:37

With a skeleton project in hand, let's wire up the views. Dipping our toes into Material UI requires adding it as a dependency to src/cljs/deps.edn:

{:npm-deps {"@material-ui/core"  "4.9.13"
            "@material-ui/icons" "4.9.1"}
 ...}

Arthur11:12:08

It happens I guess. Just add these deps to your package.json and you should be good to go

Steiner14:12:32

hey, I create a file here

Steiner14:12:11

and now I want to know how to use hello in main.clj ?

delaguardo14:12:15

Instead of square brackets around :use you need to use parentheses. (ns main (:use [com.company.utils])) ps: general advice to prefer :require with alias instead of :use in ns form. it should help you further maintain your codebase

Steiner14:12:15

may I ask, how to use require in this file ?

delaguardo14:12:20

Which tool you use to prepare classpath for your project? leiningen, clojure cli or something different?

Steiner14:12:50

I run this project in replit

solf14:12:04

You don’t have a project file that tells clojure where to look for files. In your example, using clojure tools, adding a file deps.edn at root with the followig:

{:paths ["." "com"]}
makes it work

👍 1
delaguardo14:12:22

> may I ask, how to use `require` in this file ? (ns main (:require [com.company.utils :as utils])) (utils/hello "world")

Steiner14:12:57

@U7S5E44DB what is deps.edn is this new feature ?

delaguardo14:12:21

https://www.clojure.org/guides/deps_and_cli it is the part of clojure cli (replit is using it in the background)

solf14:12:05

replit uses clojure cli, or lein? They’re asking me to signup to run clojure and I don’t want to

Nitin17:12:34

Hi, I am reading the book Programming Clojure and trying the examples in repl as I read. While trying examples from the chapter on Specifications this works (s/def :bowling/roll #{0 1 2 3 4 5 6 7 8 9 10}) while this fails (s/def ::bowling/roll #{0 1 2 3 4 5 6 7 8 9 10}) I tried googling, but nothing concrete came up. What am I doing wrong?

λ ~/src/code/ clj
Clojure 1.9.0
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (s/def :bowling/roll #{0 1 2 3 4 5 6 7 8 9 10})
:bowling/roll
user=> (s/def ::bowling/roll #{0 1 2 3 4 5 6 7 8 9 10})
RuntimeException Invalid token: ::bowling/roll  clojure.lang.Util.runtimeException (Util.java:221)
#{0 7 1 4 6 3 2 9 5 10 8}
RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException (Util.java:221)

seancorfield17:12:04

::bowling/roll will try to resolve bowling as an alias to a namespace -- but it isn't, which is why it fails.

gratitude 3
seancorfield17:12:29

(! 653)-> clj
Clojure 1.10.3
user=> (ns example)
nil
example=> (in-ns 'user)
#object[clojure.lang.Namespace 0xa10c1b5 "user"]
user=> (require '[example :as ex])
nil
user=> :ex/foo
:ex/foo
user=> ::ex/foo
:example/foo
user=> 
Does that help explain it @rathi.k.nitin?

Nitin17:12:54

Yes I got it. thank you so much.

stopa18:12:34

Hey team, noob q: Is there a “multiline” (read-line)? I want a user to be able to type in multiline input, and only receive the string once they press enter.

tschady18:12:19

I don’t think so, but if you line-seq the input, you can take-while until you get your chosen marker

stopa18:12:02

Thanks tschady! This oculd work. One issue I’m having though: It doesn’t seem to detect “enter” as a marker

tschady18:12:57

would that be an empty line then?

stopa18:12:52

Unfortunately it also returns an empty line for “shift enter”.

stopa18:12:03

(Intention is for shift enter to add \n)

phronmophobic20:12:00

You can just use the java.io.Reader interface of *in* directly

Stuart19:12:32

Anyone used clj-antlr to parse tsql ?

Stuart19:12:44

I tried to use the grammar from here https://github.com/antlr/grammars-v4/tree/master/sql/tsql But when I try:

(def sql (antlr/parser "grammar/tsql.g4" {:case-sensitive? false}))
I just get pages and pages of errors in the terminal, that look like clj-antlr doesnt like the grammar file 😞 Errors like
error(50): /mnt/c/Users/stuarts/Source/___TESTREPOS/__Clojure/messing/grammar/tsql.g4:140:13: syntax error: '"' came as a complete surprise to me
error(50): /mnt/c/Users/stuarts/Source/___TESTREPOS/__Clojure/messing/grammar/tsql.g4:140:20: syntax error: '-' came as a complete surprise to me
error(50): /mnt/c/Users/stuarts/Source/___TESTREPOS/__Clojure/messing/grammar/tsql.g4:140:25: syntax error: '-' came as a complete surprise to me
error(50): /mnt/c/Users/stuarts/Source/___TESTREPOS/__Clojure/messing/grammar/tsql.g4:140:38: syntax error: '"' came as a complete surprise to me
error(50): /mnt/c/Users/stuarts/Source/___TESTREPOS/__Clojure/messing/grammar/tsql.g4:140:48: syntax error: '"' came as a complete surprise to me
error(50): /mnt/c/Users/stuarts/Source/___TESTREPOS/__Clojure/messing/grammar/tsql.g4:140:69: syntax error: '-' came as a complete surprise to me

grierson21:12:12

How do I clj -X:main when I'm not in the same dir as deps.edn?

dpsutton21:12:50

-X:main would have no meaning without deps.edn. Why do you want to do this?

grierson21:12:54

I have a multi module project so I want a top level Makefile that can execute each project individually

grierson21:12:40

project/
    Makefile
    serviceA/
        deps.edn
    serviceB/
        deps.edn

emccue21:12:35

ah so don’t

grierson21:12:20

What would I do instead @U3JH98J4R?

emccue21:12:27

1. you can make a toplevel deps.edn that will have a build script that uses tools.build to run commands in the context of each project 2. have your script cd into each directory as appropriate

👍 1
emccue21:12:09

example with babashka tasks of (2):

{:paths ["bin"]
 :min-bb-version "0.7.0"
 :tasks {:requires ([tasks])
         backend:start {:doc "Starts the backend-end application (backend:start-db must be run first)"
                        :task (shell {:dir "./service"} "clj -M -m your-service.main")}
         }
 }

👍 1
emccue21:12:52

example derived from a polylith example of (1)

(ns build
  "The build script for the example of the poly documentation.
   Targets:
   * uberjar :project PROJECT
     - creates an uberjar for the given project
   For help, run:
     clojure -A:deps -T:build help/doc
   Create uberjar for command-line:
     clojure -T:build uberjar :project command-line"
  (:require [ :as io]
            [clojure.tools.build.api :as b]
            [clojure.tools.deps.alpha :as t]
            [clojure.tools.deps.alpha.util.dir :refer [with-dir]]
            [org.corfield.build :as bb]))

(defn- get-project-aliases []
  (let [edn-fn (juxt :root-edn :project-edn)]
    (-> (t/find-edn-maps)
        (edn-fn)
        (t/merge-edns)
        :aliases)))

(defn- ensure-project-root
  "Given a task name and a project name, ensure the project
   exists and seems valid, and return the absolute path to it."
  [task project]
  (let [project-root (str (System/getProperty "user.dir") "/projects/" project)]
    (when-not (and project
                   (.exists (io/file project-root))
                   (.exists (io/file (str project-root "/deps.edn"))))
      (throw (ex-info (str task " task requires a valid :project option") {:project project})))
    project-root))

(defn uberjar
  "Builds an uberjar for the specified project.
   Options:

   File must contain an :uberjar alias
   which must contain at least :main, specifying the main ns
   (to compile and to invoke)."
  [{:keys [project uber-file] :as opts}]
  (let [project-root (ensure-project-root "uberjar" project)
        aliases      (with-dir (io/file project-root) (get-project-aliases))
        main         (-> aliases :uberjar :main)]
    (when-not main
      (throw (ex-info (str "the " project " project's deps.edn file does not specify the :main namespace in its :uberjar alias")
                      {:aliases aliases})))
    (binding [b/*project-root* project-root]
      (let [class-dir "target/classes"
            uber-file (or uber-file
                          (-> aliases :uberjar :uber-file)
                          (str "target/" project ".jar"))
            opts      (merge opts
                             {:class-dir    class-dir
                              :compile-opts {:direct-linking false}
                              :main         main
                              :uber-file    uber-file})]
        (b/delete {:path class-dir})
        (bb/uber opts)
        (b/delete {:path class-dir})
        (println "Uberjar is built.")
        opts))))

emccue21:12:15

and at our work, we do neither at the moment

Ed23:12:26

@U3G3MBL9H In your makefile, just cd serviceA ; clj -X:main

👍 1