Fork me on GitHub
#clojure-russia
<
2017-01-15
>
artemyarulin07:01:45

@leov дада cider == emacs. Хз чо как про вим вааще

andre09:01:49

привет а никто с транзитом не работал?

andre09:01:12

если он встречает данные, которые он не знает, он кидает эксепшн и останавливается, можно ли как-то передать на этот случай хендлер чтобы просто "заглушку" вставить и продолжить дальше?

andre12:01:07

:handlerForForeign

misha13:01:50

@andre а как же:

TaggedValues

It is possible that Transit encoded data will contain a semantic type that a processing application does not have a read handler for. In that case, the encoded value cannot be decoded and is returned as an instance of a special TaggedValue type with two properties, a tag and a value (details vary by programming language). TaggedValues can be inspected by application code if required. If a TaggedValue instance is written with Transit, the tag and value are used for the encoded form. ensuring that TaggedValues roundtrip correctly.

andre13:01:21

ну да

andre13:01:30

это уже ридер

andre13:01:03

а я про райтер спрашивал

misha13:01:24

так бы сразу

misha13:01:48

и вообще, ты про clj или cljs ?

andre13:01:38

я делаю визуально отображение в виде дерева структур данных cljs, и передаю их на визуализацию через сокет, там транзит

andre13:01:42

ну вот когда в данных есть левак какой-то от js , то write транзита вылетал с эксепшеном

andfadeev19:01:56

привет, а подскажите best practice, нужна функция которая принимает 1 обяз. аргумент + допустим 2 опциональных, в разных комбинациях, какой вариант лучше?

;;1
(defn some-func
  ([required]
    (some-func required nil nil))
  ([required opt1]
    (some-func required opt1 nil))
  ([required opt1 opt2]
    (println "do smthing" required opt1 opt2)))
;;2
(defn some-func1
  ([required]
    (some-func1 required nil))
  ([required {:keys [:opt1 :opt2]}]
   (println "do smthing" required opt1 opt2)))
;;3
(defn some-func2 [required & [opt1 opt2]]
  (println "do smthing" required opt1 opt2))
;;4 что-то еще?

misha19:01:34

3 пайдёт

andfadeev19:01:03

меня напрягает что nil надо будет явно передать если захочу (some-func2 nil "opt2 val")

andfadeev19:01:36

как и в первом варианте

andfadeev19:01:03

а если завернуть в мапу то не надо

andfadeev19:01:26

+ в третьем варианте нет чека на arity изза варарга

misha19:01:48

такое еще есть

(defn configure [val & {:keys [debug verbose]
                        :or {debug false, verbose false}}]
  (println "val =" val " debug =" debug " verbose =" verbose))

(configure 10)
;;val = 10  debug = false  verbose = false

(configure 5 :debug true)
;;val = 5  debug = true  verbose = false

;; Note that any order is ok for the kwargs
(configure 12 :verbose true :debug true)
;;val = 12  debug = true  verbose = true

misha19:01:04

The use of keyword arguments has fallen in and out of fashion in the Clojure community over the years. They are now mostly used when presenting interfaces that people are expected to type at the REPL or the outermost layers of an API. In general, inner layers of the code find it easier to pass options as an explicit map.

misha19:01:34

ты опоздал на вечеринку opieop

andfadeev19:01:06

спс за инфу

seryh20:01:20

через defmulti еще можно