Fork me on GitHub
#beginners
<
2017-07-12
>
nbardy14:07:11

Is there a shorthand way to require nested namespaces? i.e

(ns baz
  (:require 
    [foo
      [bar :as b]
      [cat :as c]]))
To require the namespaces foo.bar

noisesmith16:07:38

prefix lists are valid but they have unpleasant side effects for some common workflows

noisesmith16:07:50

for example they make it harder to grep for usage of a namespace

a1314:07:13

maybe smth like (:require [foo [bar :as b] [cat :as c]]) ?

a1314:07:53

oh, you wrote exactly that

ajs20:07:56

@noisesmith what are you using now instead of emacs?

noisesmith20:07:28

I switched to vim because it doesn’t require chording as much as all the other editors do, and that’s nicer for my wrists. I used evil for a while but eventually using vim was simpler and more consistent.

moogey20:07:45

did you remap your capslock?

seancorfield20:07:45

@ajs I'm another "ex-Emacs" Clojurian -- I switched to #protorepl about six months ago and I've been very happy with that.

seancorfield20:07:02

(and I started off with Emacs key bindings installed in ProtoREPL to ease the transition but recently -- maybe a month ago? -- pulled those out and went back to stock key bindings, with a handful of additional ones to expose more paredit functionality)

ajs20:07:05

@seancorfield i've never heard of protorepl before, now i'm curious; @noisesmith did you find the vim/clojure integration (paredit, repl, etc) to be straightforward?

noisesmith20:07:41

vim-sexp is better than paredit because it matches the functionality / editing model of vim itself imho

noisesmith20:07:04

the repl works but honestly I was never one to use the repl integration much

ajs20:07:41

@seancorfield you are talking about the atom package?

seancorfield20:07:06

I always have a live REPL running in Atom. I love ProtoREPL's ability to evaluate forms inline and show results right there in the source editor (as well as the REPL).

moogey20:07:23

man, I tried for maybe 30 minutes last night and couldn’t get proto-repl-charts to work with a project. 😞 (Until another day)

fedreg21:07:16

Hi all, can’t seem to get my brain around this and wondering if someone could point me in the right direction. I have two collections. One is small (call it smallList) and is a list of lists each with two elements ((A B) (C D) (E F)) the second is larger (call it bigList) and is a vector of vectors each with 8 elements: [[ A B 1 2 3 4 5 6 ] [ C D 1 2 3 4 5 6] ...] I need to return all items from bigList whose first two elements match each of the lists in smallList. For example: (nth smallList 0) equals (take 2 (nth bigList 0) so I would like the entire (nth bigList 0). Couldn’t figure out how to do that since count bigList is much larger than count smallList. Hope that makes sense!!! Thanks for investing the time to read all this!

dpsutton21:07:40

so smalllist is just a set of tags. and you want to filter biglist down to the members who's first two members are members of that set of tags?

noisesmith21:07:56

sounds like a job for a hash-map

dpsutton21:07:34

so turn smalllist into a set. (into #{} smalllist)

noisesmith21:07:54

oh, right, a set is a better match

dpsutton21:07:35

and the predicate is (fn [list] (when (contains? smallListSet (take 2 list)))

dpsutton21:07:11

* some parens assembly required

noisesmith21:07:57

#(when (smallListSet (take 2 %)) %)

dpsutton21:07:12

yeah thanks

noisesmith21:07:36

well that’s built to be a filter rather than predicate… but yeah

dpsutton21:07:46

oh just get rid of the when and just use the contains

noisesmith21:07:07

you don’t even need contains, a set is a function on membership that returns the item

noisesmith21:07:14

and you’ll never be looking up false or nil

mobileink21:07:23

@seancorfield "ex-emacs"??? you're gasting my flabbers. code editing aside, i can hardly imagine life without dired, bookmarks, etc etc. proto-repl has similar? what about cross platform? i use osx but often must use linus and windows.

seancorfield21:07:37

Yes, Atom is cross-platform. I don't miss any Emacs features but YMMV. I do sometimes miss having multiple REPLs open but I've changed my workflow a bit to make that less of an issue.

mobileink21:07:06

hmm, you got me actually thinking about emacs alternatives, which i never thought would happen, heh. if you don't mind: how is life better with protorepl? is it clojure-specific? (i also need to edit c, c++, js, etc.)

seancorfield21:07:13

I also edit JS and some other stuff. Atom has pretty broad support for languages. Atom is a nice, modern, well-maintained editor and its packages are also (mostly) well-maintained -- and it has a nice auto-update setup so you know when there are updates and what's changed in them. I got tired of Emacs' old-fashioned, clunky feel.

seancorfield21:07:04

On the Clojure-specific side, the ProtoREPL chart stuff is very cool for visualizing data while you're working with it, and the REPL integration directly inline in the editor panel is sweet.

seancorfield21:07:15

Much depends on what you rely on in Emacs and what you'd miss.

seancorfield21:07:22

I first got started with Emacs back in the 17.x days, lived through the 18.x period and stopped using it just as 19.x was coming on stream. Then I went back to it several years ago -- because of Clojure -- just as 24.x was coming on stream. So I have a lot of years of Emacs under my belt.

mobileink22:07:20

i started using emacs on os2 in the 90s, buleevw it or not! how,much time wpuld you allocate for getting used to protorepl? assuming you cannot cut over all at once.

mobileink22:07:33

separate q: assuming colleagues coming over from e.g. python or java. would you recommend protorepl in such cases? (not knowing which tools they areused to)

seancorfield23:07:14

Python, yeah. I'd expect Atom/ProtoREPL to be familiar enough (or at least, not as different as Emacs!).

seancorfield23:07:51

Java, hard to say. Most Java folks are used to a full IDE (Eclipse, IntelliJ) because Java's such a crappy language to use without all that IDE support.

seancorfield23:07:02

As for switching from Emacs to ProtoREPL. I set ProtoREPL up (with Emacs key bindings) on both my machines over a couple of days and got it Emacs-y enough to be comfortable, then the next Monday I just shut Emacs down and vowed not to use it again for at least a week.

seancorfield23:07:00

The first couple of days were painful as some of the buffer/window navigation shortcuts didn't translate over but by the end of the week it was mostly plain sailing. I stuck with it another week without Emacs and by that point I was fully productive.

seancorfield23:07:21

The key is just forcing yourself to use a new tool and not "sneaking back" to the old one.

seancorfield23:07:19

It was much the same when I stripped the Emacs key bindings from Atom and re-enabled the defaults. Took a few days to realize I needed to re-surface some paredit key bindings, but otherwise it was relatively easy 😸

seancorfield23:07:38

Some of my Atom setup is here https://github.com/seancorfield/proto-repl-setup (not my core config tho' since it's not yet portable across Mac/Win).

mobileink00:07:21

but all things considered you think the switch was worth the trouble?

seancorfield01:07:23

Yeah, definitely. I was always frustrated at how fragile Emacs configurations could be and how difficult it was to stay current on packages without things breaking. I'd originally hand-built my Emacs setup but it wasn't exactly "best practice" so I switched to Emacs Live (from the Overtone folks) but that used special packaging for modules -- and wasn't being very actively maintained after a while! -- so I switched to Prelude (from the CIDER folks) which was OK but too complex and a bit too opinionated. So, bottom line, I was never 100% happy with the configuration/setup side of Emacs. That's definitely not a concern with Atom/ProtoREPL and I'm finding the modernity of Atom pleasing. It just feels easier to work with, easier to customize.

seancorfield01:07:15

That all said, editors are definitely subjective things -- and Emacs/CIDER is still far and away the most popular Clojure setup, followed by Cursive, then vim, with Atom in 4th place (although Cognitect's survey noted: "The most interesting development was the rise in the use of Atom which was a new choice and selected by 6% of respondents." -- but that compares to 47% for Emacs, 26% for Cursive, and 12% for vim so...).

mobileink02:07:12

well, you’ve convinced me to at least take a look. I luvs me my emacs, but i have to admit it’s kinduv a pain in the arse. scratch that (no pun intended), major pain in the arse. just got a new windows machine at work and am looking forward to spending 2-3 weeks getting emacs running properly; huzzah! I personally would stick with emacs, but recommending it to colleagues is, let’s face it, a non-starter.

seancorfield02:07:06

That was part of the issue for me. We cross-trained a few folks to Clojure and Emacs was very alien to them. My teammate now is a huge Emacs fan, but he also runs Linux as his desktop etc. But it's good to have a solid, modern (non-Emacs) option for any new folks we add. And I like having a much-more straightforward config I can set up in maybe 30 minutes tops on a new machine.

seancorfield02:07:20

Anyways, dinner time here. Then I'll be back on later.

mobileink02:07:50

yeah. let’s face it, emacs is an alpha-geek kinda thing. i mean it is incredibly awesomenistic, but it ain’t for everybody. if you do emacs you get bonus points, but if you don’t it does not mean you’re not a badass. not a vim guy myself, but i reckon a vim master is about as much a badass as an emacs maestro.

mobileink02:07:04

the atom equiv of elisp is …? https://atom.io/packages/script seems too good to be true.

seancorfield03:07:47

That looks like a generic REPL for various languages. Atom itself is scripted with JS (unfortunately). ProtoREPL is written in CoffeeScript (very unfortunately).

seancorfield03:07:00

But I suspect you could program it in ClojureScript...

seancorfield03:07:37

Been meaning to ask, why the "mobileink" nickname?

mobileink05:07:52

way back when, was heavily involved in typesetting. even had a job writing typesetting code, and still harbor some fading hopes of writing the One True Typesetting Engine, ha ha.

fedreg21:07:06

awesome! thanks for the help! Not sure what all those do yet but should be straight forward to figure out. Thanks again!

dpsutton21:07:08

user> (let [smallset (into #{} '((a b) (c d)))]
        (filter #(contains? smallset (take 2 %))
                '((a b 1 2 3 4)
                  (c d 1 2 3 4)
                  (e f 1 2 3 4))))
((a b 1 2 3 4) (c d 1 2 3 4))

dpsutton21:07:19

take 2 grabs the first two of a list. Contains checks if an element is in a collection. Filter returns a seq of elements matching that predicate. and set is a datastructure that gives O(1) membership checks

dpsutton21:07:17

which translates very literally into your requirement, "if the first two elements of a list are in this set, keep it"

fedreg21:07:19

thx. Yeah it was using the set that I was missing. Makes sense. Thanks again!

dpsutton21:07:26

https://clojuredocs.org/clojure.set for some info about set and the operations on it. set is also a sequence so you can take, filter, etc. but it does not maintain order

fedreg21:07:24

Yes, worked perfectly. Thank you both!

Alex Miller (Clojure team)21:07:52

set is not a sequence. but it can provide a sequential view of the set (which is implicitly done within seq operations)

Alex Miller (Clojure team)21:07:13

In other words, sets are seqable but not seqs

seancorfield21:07:18

(seq? #{1 2 3}) => false; (seqable? #{1 2 3}) => true

seancorfield21:07:31

Yeah, what he said ☝️:skin-tone-2:

dpsutton21:07:36

whoops. my bad

bwstearns22:07:16

I am just picking up Clojure again after about 8 months of being busy with work and trying to use it for XML handling. I’m trying to (require clojure.xml) but it’s not autocompleting in the repl and it says not found when I type it. https://clojure.github.io/clojure/clojure.xml-api.html seems to indicate that it’s part of the standard library. Did it move or something?

dorab22:07:04

You might need either (require 'clojure.xml) or (require '[clojure.xlm :as xml])

bwstearns22:07:44

Thanks, that seemed to move the ball forward a little

project.core=> (require 'clojure.xml)
nil
project.core=> (xml/parse)

CompilerException java.lang.RuntimeException: No such var: xml/parse, compiling:(/private/var/folders/q6/xdxb066n7mv6qg0wb8nx1qf80000gp/T/form-init8575028924345994165.clj:1:1) 

bwstearns22:07:13

Oh, got it working. Thanks very much!