Fork me on GitHub
#beginners
<
2019-08-21
>
sova-soars-the-sora03:08:45

I'm making an online japanese vocabulary quiz for the kanji (imported chinese glyphs) and their compounds.

sova-soars-the-sora03:08:10

Someone suggested that it would be cool to select which glyphs you already know so you can be fed only compounds that satisfy from the set of "known glyphs" you indicate

sova-soars-the-sora03:08:13

so i'm working on that! i'm stoked, it's pretty cool, but there are some weird things. is it okay to store these individual kanji like so?

(def all-tango (atom [{:tango "日" :kanji "日"}
{:tango "月" :kanji "月"}
{:tango "一月" :kanji ["月" "一"]}
{:tango "十月" :kanji ["月" "十"]}
{:tango "同月" :kanji "月"}
{:tango "会う" :kanji "会"}
{:tango "出る" :kanji "出"}
{:tango "出す" :kanji "出"}																						{:tango "同じ" :kanji "同"}]))

(def individual-kanji (atom [{:kanji "日"} {:kanji "会"}	{:kanji "同"}	{:kanji "月"}	{:kanji "一"}	{:kanji "十"}	{:kanji "出"}]))

sova-soars-the-sora03:08:15

As you can see, the individual pieces are noted, and you can click on them on the app and add them to an active set, i want to compare the active set with the :kanji list in the all-tango. (Tango means "vocabulary, words") so you can see each word and then what kanji are part of it.

sova-soars-the-sora03:08:41

Right now I don't know how to compare a collection of "known kanji" against the constituent parts of each vocab word in the all-tango atom.

salam04:08:21

@sova sets are perfect for this use case. you may use a set to store the constituent kanji of a tango (e.g., {:tango "一月" :kanji #{"月" "一"}}). you may use another set to store the "known kanji" (e.g., (def known-kanji #{"日" "同" "一" "出"}). from there on, you can use clojure.set/subset? to filter out tango(s) from the tango vector whose constituent kanji set is a subset of the known-kanji set.

1
salam15:08:50

i’m not in front of a computer right now. but i have a question: why are you keeping all-tango and individual-kanji in atoms?

salam15:08:41

it seems like these represent a known set of things that you can pick elements from and shouldn’t have a reason to change at runtime.

sova-soars-the-sora15:08:58

Great question! I'm making an online quiz. Maybe you can help me figure out what's most natural in Clojure. There's a set of all characters, you can click on them and add them to a known kanji atom (changes at run-time, during runtime) because it'll generate quizzes for you on compound words based on the ones you know.

sova-soars-the-sora15:08:46

Tango and All-Kanji never change, like you say, so what's a more relevant data structure? I've ingrained the atom access pattern it's all i use! haha

salam17:08:51

this is how i would do this: 1) figure out a way to get a list of tango from all-tango based on known-kanji for one round of the game (i.e., state for a single round). 2) leveraging what's in 1), use loop/`recur` to generate state for each round of a continuous game.

sova-soars-the-sora21:08:21

that's great. thank you, i agree! i didn't think about loop and recur, i will have to employ them !

sova-soars-the-sora22:08:06

I got it working. Set thinking was the way to go. I do a simple check if the intersection of kanji and the compounds is a superset of the compounds that make up a compoundword, and if that's true then i print it out. works very pretty so far ^_^

🎉 1
sova-soars-the-sora14:08:40

I need some help writing that filter

Ian Fernandez14:08:11

I'm using deps.edn in clojure in macOS

Ian Fernandez14:08:24

but It's not detecting my namespaces

Ian Fernandez14:08:37

{:paths   ["src/main"]
 :deps    {org.clojure/clojure {:mvn/version "1.10.1"}}
 :aliases {:test {:extra-paths ["test/main"]
                  :extra-deps  {lambdaisland/kaocha {:mvn/version "0.0-529"}}
                  :main-opts   ["-m" "kaocha.runner"]}}}

Ian Fernandez14:08:45

it's like this the deps.edn

Ian Fernandez14:08:06

the tree of files is:

.
├── README.md
├── bin
│   └── kaocha
├── deps.edn
├── src
│   └── main
│       └── core.clj
└── test
    └── main
        └── core_test.clj

Ian Fernandez14:08:49

the namespaces are: and for core.clj =>

(ns main.core)
and for core_test.clj =>
(ns main.core-test)

Ian Fernandez14:08:21

is there something wrong?

uosl14:08:36

could you try changing :paths to only "src"?

clj 1
Ian Fernandez14:08:00

it worked, why

uosl14:08:56

np! the namespaces start from the path, so with "src/main" it was expecting to find the files in src/main/main/core.clj.

👍 2
uosl14:08:34

you should make the same change in :extra-paths as well

robertfw18:08:03

I am defining a rather long regex and am trying to split it over multiple lines. Currently I'm using re-pattern and constructing my string up of multiple fragments split over a few lines, though this means having to double escape. Is there a way to build up a regex over multiple lines without having to perform that double escaping? (e.g., #"\d{2}" must be written "\\d{2}")

noisesmith18:08:58

user=> (re-pattern (str #"\d" #"\w"))
#"\d\w"

noisesmith18:08:48

you can use the regex reader by using the #"" notation for each of the substrings

noisesmith18:08:52

it combines as expected

noisesmith18:08:16

you can also use format with %s instead of str if that makes things clearer (%s also does the right thing with an re input)

Michael Stokley20:08:06

i have a hash map with a key :@timestamp

Michael Stokley20:08:41

when i try to get the value it throws a syntax error Invalid token: :

Michael Stokley20:08:02

i've tried putting it in double quotes and escaping it with \

Michael Stokley20:08:04

i guess i could change it into a string... any other options folks may know of?

ghadi20:08:37

Sounds like elasticsearch. (keyword "@timestamp") should get you going

💯 1
ghadi20:08:57

It is constructable but not readable as a literal