Fork me on GitHub
#off-topic
<
2021-02-05
>
dpsutton07:02:43

i just learned about clojure.tools.macro, in particular symbol-macrolet. I have an urge to overuse the heck out of this. a tasteful example: https://github.com/swannodette/logic-tutorial/blob/master/src/logic_tutorial/tut3.clj#L16

Gleb Posobin19:02:33

I didn't get that example. What is it doing, what is lvar?

dpsutton19:02:15

Lvar is a logical variable which is unbound. It can unify to anything.

Max20:02:12

Why doesn’t (let [_ (lvar)] …) work in this case?

dpsutton20:02:27

it doesn't because then they are all the same lvar. but rather than write (== [(lvar) (lvar) [(lvar) (lvar) 'milk (lvar) (lvar)] (lvar) (lvar)] hs) he made a macro that the form _ expands to (lvar)

dpsutton20:02:39

(macroexpand
  '(macro/symbol-macrolet [_ (lvar)]
                          (all
                            (== [_ _ [_ _ 'milk _ _] _ _] hs)                         
                            (firsto hs ['norwegian _ _ _ _])                         
                            (nexto ['norwegian _ _ _ _] [_ _ _ _ 'blue] hs)       
                            (righto [_ _ _ _ 'ivory] [_ _ _ _ 'green] hs)         
                            (membero ['englishman _ _ _ 'red] hs)                    
                            (membero [_ 'kools _ _ 'yellow] hs)                      
                            (membero ['spaniard _ _ 'dog _] hs)                      
                            (membero [_ _ 'coffee _ 'green] hs)                      
                            (membero ['ukrainian _ 'tea _ _] hs)                     
                            (membero [_ 'lucky-strikes 'oj _ _] hs)                  
                            (membero ['japanese 'parliaments _ _ _] hs)              
                            (membero [_ 'oldgolds _ 'snails _] hs)                   
                            (nexto [_ _ _ 'horse _] [_ 'kools _ _ _] hs)          
                            (nexto [_ _ _ 'fox _] [_ 'chesterfields _ _ _] hs))))
(do
 (all
  (==
   [(lvar) (lvar) [(lvar) (lvar) 'milk (lvar) (lvar)] (lvar) (lvar)]
   hs)
  (firsto hs ['norwegian (lvar) (lvar) (lvar) (lvar)])
  (nexto
   ['norwegian (lvar) (lvar) (lvar) (lvar)]
   [(lvar) (lvar) (lvar) (lvar) 'blue]
   hs)
  (righto
   [(lvar) (lvar) (lvar) (lvar) 'ivory]
   [(lvar) (lvar) (lvar) (lvar) 'green]
   hs)
  (membero ['englishman (lvar) (lvar) (lvar) 'red] hs)
  (membero [(lvar) 'kools (lvar) (lvar) 'yellow] hs)
  (membero ['spaniard (lvar) (lvar) 'dog (lvar)] hs)
  (membero [(lvar) (lvar) 'coffee (lvar) 'green] hs)
  (membero ['ukrainian (lvar) 'tea (lvar) (lvar)] hs)
  (membero [(lvar) 'lucky-strikes 'oj (lvar) (lvar)] hs)
  (membero ['japanese 'parliaments (lvar) (lvar) (lvar)] hs)
  (membero [(lvar) 'oldgolds (lvar) 'snails (lvar)] hs)
  (nexto
   [(lvar) (lvar) (lvar) 'horse (lvar)]
   [(lvar) 'kools (lvar) (lvar) (lvar)]
   hs)
  (nexto
   [(lvar) (lvar) (lvar) 'fox (lvar)]
   [(lvar) 'chesterfields (lvar) (lvar) (lvar)]
   hs)))

Max20:02:11

Aaaah, makes sense

dpsutton20:02:48

@UQ4RJ22EA unify means to unify the meaning of a logical variable. (unify (A 3) (2 3)) would unify the logical variable A with 2. I made up the signature of unify here but that's the general idea

thanks 4
👍 4
Stuart12:02:51

I have 2 screens on our customers system that are meant to show the same data, they don't. It doesn't match up all the time. I asked what I thought was a simple question, "which one is wrong?". "Don't know". Ok, I'll rephrase, for the current settings... What is the correct vlaues that should be shown? "Don't know." ".... Do you see my problem?" "It needs fixed." "Yes, it does, but how am I supposed to fix it if I don't know what the values to be displayed actually are or what one is wrong (they could be both be wrong)." "It needs fixed."

😀 3
Tomas Brejla13:02:08

... but DID YOU FIX IT? 😄

Stuart13:02:33

If by fix, you mean I went and made a cheese toastie, then yes.

👏 3
Stuart12:02:15

and the SQL behind both of them is wildly different, and both equally impenetrable.

🙂 3
facepalm 6
caumond12:02:18

A problem well defined is a problem half solved. Henri Poincarré. It seems you're not there !

9
manutter5112:02:59

When the work request is “I don’t know what I want,” then “I don’t know how to do that” is a valid implementation.

😄 6
Stuart12:02:24

I want to scribble that all over the people I work withs faces with permanent marker

😆 6
manutter5112:02:50

I know that feeling.

caumond12:02:04

it's my day to day

caumond12:02:40

one step deeper @qmstuart, I have guys matching your description AND not agreeing with my solution.

dgb2312:02:06

There seems to be a DRY violation. Two separate things (SQL queries) represent the same knowledge.

dgb2312:02:28

Sometimes you can tackle the problem by disentangling and the original intent (and bug) becomes clear.

dgb2312:02:32

In your case it seems you need to do that. So take it as a fun puzzle 😂

Oliver Lieu13:02:28

[For Hire] [Remote] Hello, everyone. I am a full-stack developer specialized in MERN stack as well as Laravel, MySQL, Javascript/jQuery, CSS/SCSS, HTML5. My focus is always on building the best secure, reliable, and with good User Experience websites. [25 USD Hourly] Skills: -React -Vue.js -Node.js -Express.js -Laravel -Mongo DB -MySQL -JavaScript/jQuery -CSS/SCSS -HTML5 I think I can help you with my skills as a developer. If you are interested in me, please inform me. I am open to work and can start right now. It'll be my great pleasure to work for you. Thanks.

orestis15:02:58

Hi there, this is considered spam for a few reasons: • wrong channel • no obvious links with Clojure

6
Jeff Evans15:02:58

wait, so it was an on-topic post? 😆

Mike16:02:21

It's interesting that posts in #off-topic have to be in a way on-topic.

Jeff Evans16:02:07

I smell a Monty Python skit

souenzzo19:02:52

breaking news: clojure isn't a superset of edn: '1 is a valid symbol in edn But in clojure it is (quote 1)

Vincent Cantin07:02:45

''1 evaluates to the '1 symbol

borkdude19:02:17

' is a valid symbol in EDN, also '1 whereas in Clojure this is expanded into the special form (quote 1)

borkdude19:02:40

not sure if it's intended that symbols can start with a quote in EDN though

noisesmith20:02:38

of course (symbol "'1") works

noisesmith20:02:21

also 'foo/'1