Fork me on GitHub
#clojure-dev
<
2018-10-26
>
gfredericks12:10:36

harking back to a discussion about the #< dispatch in the reader, I found something that still prints that way: (with-local-vars [v 42] v)

andy.fingerhut23:10:21

Wow, with-local-vars has remarkably few usages found by CrossClj. It is kind of a strange name for something that can so easily return the "local" thing.

gfredericks23:10:06

I have literally never heard of anybody using it ever

gfredericks23:10:47

user=> (let [v (with-local-vars [v 42] v)] (var-set v 12) @v)
Evaluation error (IllegalStateException) at clojure.lang.Var.set (Var.java:226).
Can't change/establish root binding of: null with set
in case you're curious what you can do with it after returning it

gfredericks23:10:14

also

user=> (let [v (with-local-vars [v 42] v)] (push-thread-bindings {v 12}) @v)
12

bronsa00:10:55

push-thread-bindings w/o a matching pop-thread-bindings is scary

bronsa00:10:09

do it enough times and you'll massively mess your REPL state

andy.fingerhut23:10:27

Out of a dozen or so uses I have found by CrossClj, every one of them uses it to create and return an anonymous Var 🙂

bronsa23:10:57

I'm guilty of that :)

andy.fingerhut23:10:59

And about 4 of those are copies of tools.reader

gfredericks23:10:23

can we call it a feature used by @bronsa then?

andy.fingerhut23:10:59

There are other hackers using it to create unnamed Vars, too. He isn't the only one.

gfredericks23:10:13

but I want to believe he is

andy.fingerhut23:10:22

Looks like this clown named gfredericks has a project that uses it.

bronsa23:10:47

it's an exclusive club

gfredericks23:10:35

is the only difference between var-set and set! whether or not you have to hash-quote?

bronsa23:10:43

(modulo evaluation rules)

gfredericks23:10:15

...meaning the obvious ones that relate to any macro?

bronsa23:10:25

set! is a special form not a macro

bronsa23:10:57

but yeah it doesn't really behave any differently then if it were a macro

gfredericks23:10:13

and it could be one since var-set exists, eh?

bronsa23:10:46

yes, except by being a special form it can emit sligthtly better bytecode

gfredericks23:10:01

you could get rid of every special form except interop and just put everything in RT, is that right?

andy.fingerhut23:10:08

I think it should be renamed with-local-vars-but-here-is-the-exit-door-thanks-for-visiting

2
gfredericks23:10:55

weeeeeeeeellllllllllllllllllll okay

bronsa23:10:57

anything that introduces lexical bindings needs to be a special form

gfredericks23:10:07

sorry I've had a couple beers

bronsa23:10:04

we need a #clojure-tipsy-and-late-at-night-banter channel IMO

👍 2
bronsa23:10:12

coincidentally (not really), most of the special forms do exactly that

gfredericks23:10:33

okay but interop and fn would be enough

gfredericks23:10:26

no one expects the spanish list of special forms

😂 1
andy.fingerhut23:10:28

Difficult to win an argument with the author of tools.analyzer on corner cases.

😛 2
gfredericks23:10:42

I've misplaced my inhibitions

gfredericks23:10:09

our three weapons are interop, fn, and recur

gfredericks23:10:26

and try that's four weapons

bronsa23:10:45

well, hard to do imperative code w/o do

andy.fingerhut23:10:53

Reminds me of one of the weird cases bronsa has fixed in tools.analyzer - someone redefining catch as a macro

gfredericks23:10:17

(defmacro do [& forms] `((fn [] [email protected])))

bronsa23:10:19

reminds me I still have to fix that :arglists bug you reported

bronsa23:10:30

that's cheating, fn uses the do machinery internally

gfredericks23:10:39

also try could make a couple fns and pass them to RT

gfredericks23:10:49

it's not cheating, I'm assuming fn is a special form

andy.fingerhut23:10:57

Not high priority -- if I don't file something, I will probably have forgotten about it within 2 days.

andy.fingerhut23:10:32

Which should be obvious by the number of times I have filed different variations on the same bug 🙂

bronsa23:10:26

@gfredericks if would probably be the other one, although I guess if you want to be really nasty you can macro it and thunkify the arguments

bronsa23:10:37

which you could do with try too

andy.fingerhut23:10:55

... reinventing Church numerals in 3... 2... 1....

andy.fingerhut23:10:26

Testing how to make Greek letters: lambda

andy.fingerhut23:10:56

this & that &amp; the other

bronsa23:10:14

sweajure 2.0

andy.fingerhut23:10:17

Dang it. I so totally should have written those as church numerals.

gfredericks23:10:58

(defmacro if [c t e] `(({true (fn [] ~t) false (fn [] ~f)} (boolean ~e))))

hiredman23:10:09

the problem with clojure is doing all the classical lambda calculus stuff breaks recur

bronsa23:10:21

(boolean ~e) rather

bronsa23:10:23

there you go

gfredericks23:10:57

me and @bronsa know all the standard pitfalls with implementing if using maps

bronsa23:10:11

don't know about you but I write that on my CV

👍 2
hiredman23:10:19

my favorite way to do do would be something like

(defmacro do [it & more] (if (seq more) `((fn [_#] (do [email protected])) ~it) it)) 
which also still breaks recur

🤯 1
hiredman23:10:08

I read it somewhere

andy.fingerhut23:10:03

I'm not letting you break my mind.... Averting eyes....

andy.fingerhut23:10:01

OK, reinventing Church numerals in λf.λx. f (f (f x)) … λf.λx. f (f x) … λf.λx.f x …

😂 2
andy.fingerhut23:10:17

Yes, I have spent the last few minutes very productively.

gfredericks23:10:17

That could qualify as the nerdiest pun I've ever seen