Fork me on GitHub
#clojure
<
2020-04-11
>
pinkfrog01:04:50

just to confirm, the compiler uses the function macroexpand to expand all compilers

seancorfield01:04:58

to expand all... macros?

pinkfrog01:04:32

yes. if it sees a macro

Cameron01:04:05

he's pointing out that you wrote 'expand all compilers' 👀

Cameron02:04:57

and the impression I get is indeed, a form (like (macro-blah a b c) at some point reaches the analyze function in Compiler.java (Line 6748), and that particular form will match the case

else if(form instanceof ISeq)
				return analyzeSeq(context, (ISeq) form, name);
, call analyzeSeq, analyzeSeq will early on call macroexpand1 on it (and every form like this -- or ISeq specifically -- it looks like, so function calls and I suppose 'actual' lists and what not too), here
try
	{
	Object me = macroepand1(form);
	if(me != form)
		return analyze(context, me, name);
and

Cameron02:04:05

I suppose if that indeed results in something new, it knows its a macro, and starts analyzing the new expanded form instead

Cameron02:04:54

as always, don't take this as 100% accurate -- this is my impression from looking at it recently, but its easy to get something off that way, its always best to investigate it yourself of course

Cameron02:04:58

hmm I want to look at again now, as I haven't seen the function you posted strangely oh nvm smh yes I have

Cameron02:04:58

I wonder, it looks like it calls macroexpand once in the beginning, and then calls it again (or rather, macroexpand1) during analysis / the part I posted, that's something I'm curious to look at more

jsn13:04:32

Does anyone know, by chance, what happened to clojure.contrib.dataflow? Seems like it's been deprecated for ages now, is there any modern replacement?

jsn14:04:48

Yeah, seen that, but it seems to be cljs only

seancorfield17:04:48

Many of the 60+ "old contrib" libraries never migrated out of the monolith when it was deprecated as part of the Clojure 1.3 release process -- due to having no maintainers willing to continue work on them. Here's a fairly accurate map of what did migrate and what their new names became: https://clojure.org/community/contrib_history

seancorfield17:04:04

If you wanted to revive dataflow and maintain it, you could talk to Alex Miller and see if Clojure/core would be happy to migrate it to a new repo under Contrib, or else you could fork it outside Contrib and work on it (retaining the copyright and license!).

jjttjj19:04:21

@UTQEPUEH4 FWIW a creator of javelin made a clojure version in a PR that hasn't been merged. I have used it before and it works https://github.com/hoplon/javelin/pull/40

hindol18:04:27

In Clojure, what is the idiomatic way to build multiple indices over the same data? Suppose I have a set of records and I want to look them up using different keys. If the values change, they should immediately/eventually reflect across all keys. Kind of like a database. Currently, I am just mapping/filtering over the set of things at runtime.

hiredman18:04:36

clojure.set/index

4
hindol18:04:23

This filters at runtime or is it somehow more efficient?

p-himik18:04:24

It doesn't filter anything, it builds an index. You then do the filtering based on that index.

p-himik18:04:53

Note that it's not like a DB index. It's like a LUT.

hindol18:04:11

What is LUT?

hindol18:04:24

Lookup Table?

hindol18:04:16

When the set is updated, does the index get updated?

p-himik18:04:41

No, it couldn't possibly do that because the data structures are immutable.

potetm18:04:51

The underlying structures are immutable as well.

potetm18:04:44

You can e.g. use an atom to update both the underlying structures and the indices in the same swap!

hindol18:04:04

Does in memory datascript build indices internally?

phronmophobic18:04:14

if so, yes. it will build indices internally

p-himik18:04:26

It does. But the last time I checked it (2-3 years ago), it was ~10 times slower than a regular map lookup. So I just build maps manually for the fields that I'm interested in, that's it.

phronmophobic18:04:31

> EAVT, AEVT and AVET indexes

p-himik18:04:20

Building an index, keeping it up to date, and looking stuff up (if it's just an equality lookup) are all very simple operations that require barely any lines of code.

hindol19:04:13

I will do that then. Was actually wondering if there is a common idiom using atom, ref etc. that I can use.

hindol19:04:05

Maybe using add-watch and an atom.

p-himik19:04:04

Just store your index right where you store your data, and then update them together, at all times. That's it. Whatever you use to be able to update your data you will now use for the index as well simply because the index is right there in the same data structure as the data.

✔️ 4
potetm19:04:35

add-watch is unnecessary indirection for the use case.

potetm19:04:23

But yes, in an atom is really the only way to get updates.

hindol19:04:01

Okay, thanks for the suggestions! Index and data together is what I'll do.

hiredman19:04:56

If you last looked at datascript several years ago I would not be surprised if performance has improved. The underlying sorted set used for indices in datascript has been pulled as a separate project as well

hiredman19:04:46

https://git.sr.ht/~hiredman/dset/tree/master/src/com/manigfeald/dset.clj is an example of using the sorted set from datascript outside of datascript

hindol19:04:43

Thanks! That's useful to know.

p-himik03:04:26

@U0NCTKEV8 Thanks, perhaps it has improved. But I would be incredibly surprised to find that it got comparable to the regular hash maps. After all, that's what I was needing all this time - I have never had any need for comparisons, just strict equality.

hindol09:04:03

The tagline of Datascript is "What if creating a database would be as cheap as creating a Hashmap?". I am willing to give it a shot.

jjttjj19:04:46

I want to be able to read/write round trip a (sorted-set-by my-comparator. I could make my own type backed by the sorted set, but I'd rather not have to re-implement all the protocols/methods it extends to use all the clojure core functions. This seems like it'd be doable in cljs with the IPrintWriter protocol + specify!http://clj.Am I missing a good way to do this in clj?

emil0r22:04:14

Anyone else have problems with https://github.com/hypirion/clj-xchart not rendering when running a chart? Currently on MacOS High Sierra with OpenJDK 11. Getting no errors, get back the Swing JFrame, but nothing is showing

didibus02:04:30

Always worked for me, but I only tried on Linux and with JDK 8