Fork me on GitHub
#clojure
<
2016-06-18
>
bcbradley00:06:08

Is there any use case for macros that are impossible to meet with functions?

bcbradley00:06:04

Ok, besides special forms

bcbradley00:06:50

After programming in clojure for a while I'm starting to get the feeling taht I should only use macros as a last resort

bcbradley00:06:56

they don't compose with functions

bfabry00:06:31

what do we mean by special forms? ->>? and yeah I'd say macros generally should be a last resort or used with a specific intention in mind

bcbradley00:06:57

special forms are forms that cannot be expressed with the semantics for functions

bcbradley00:06:15

for example, in any function (fn [a b c] (body) (more body))

bcbradley00:06:25

the arguments will each be evaluated

bcbradley00:06:32

so will the bodies

bcbradley00:06:36

but in an if statement

bcbradley00:06:49

(if (isThisTrue?) (this) (orThat))

bcbradley00:06:01

only this orThat will be evaluated

bcbradley00:06:03

the other won't

bcbradley00:06:11

so you can't build an if out of functions.

bfabry00:06:14

but your question was is there any use case for macros that are impossible to do with functions. now you're saying but not special forms, and defining special forms as anything that can't be done with functions. bit circular?

bcbradley00:06:01

there is a small finite number of special forms

bfabry00:06:17

you could also write (if (isThisTrue) (fn [_] (this)) (fn [_] (orThat)) if you don't care about overhead or boilerplate

bcbradley00:06:48

i can't remember the name of the paper, but early in Lisp's history it was showed that a set of special forms exists that together form a turing complete system

bfabry00:06:30

sure, iirc all you need is the lambda special form. y combinator or something like that

bcbradley00:06:55

the thing is, i think macros can do things turing machines can't do

bcbradley00:06:16

but i'm unsure

bfabry00:06:31

I don't think anything can do things turing machines can't do? isn't that what turing completeness means?

bfabry00:06:46

^(in the realm of computing)

bcbradley00:06:51

turing machines represent computation

bcbradley00:06:27

we are getting into some really abstract areas here

bcbradley00:06:41

but basically, turing machines can't tell you whether a process will finish before it finishes

bcbradley00:06:02

you can't compute whether a program will terminate

bcbradley00:06:05

or when it will terminate

bcbradley00:06:07

given its source

bfabry00:06:10

the halting problem is a problem with math, not turing machines

bcbradley00:06:20

but it brings me to a different point

bcbradley00:06:39

turing machines just aren't that good at doing anything with programs as input

bcbradley00:06:45

its not just about computing whether it will terminate

bcbradley00:06:08

its how they are constructed

bcbradley00:06:23

the semantics are hostile towards the idea of programs as values

bcbradley00:06:21

it may be possible to compute the prime factorization of a large number with two large factors

shot00:06:24

An influential mathematician of the early 20th century, David Hilbert, published his famous list of 23 problems in mathematics. The problems were unsolved at that time and were the kinds of problems whose solutions would lead to the advancement of mathematics. Later he posed another challenge which is famously known as Entscheidungsproblem (Decision problem). These problems of Hilbert had promoted vigorous investigation into the theory of computability. The two computing models that came out of that time were Alonzo Church’s Lambda Calculus and Alan Turing’s Turing Machine. Hilbert’s Decision problem asks if is it possible to devise an algorithm to solve any problem. Alan Turing answered NO to the problem. Of course, saying no is not enough. You have to prove it. Turing created an abstract computation model called Turing Machine as part of his proof.

bcbradley00:06:08

but most of the security on the internet relies on the fact that actually computing it is too intensive to do practically

bcbradley00:06:20

i see turing machines in a similar way

bcbradley00:06:39

its possible to design a program using only turing complete semantics that takes another program as input and does useful things with it

bcbradley00:06:54

but if you try to do anything involved, you will have to simulate a turing machine within a turing machine

bcbradley00:06:01

and it becomes nightmarish after that

bcbradley00:06:33

turing machines can compute anything that is computable, but that doesn't mean they are practical for every computable problem

bcbradley00:06:43

they can THEORETICALLY compute anything that is computable

bcbradley00:06:51

not PRACTICALLY

bcbradley00:06:24

for instance, turing machines were based on tape memory and sequential access, but we use random access memory

bcbradley00:06:36

so what i'm saying is that macros may or may not cover a use case in which the turing model of computation is theoretically sufficient but in practice is not pragmatic

bcbradley00:06:08

i don't know

seancorfield04:06:40

@bcbradley: Tangential but back when I was on the ANSI C++ Standards, one of the German reps posited that templates were Turing Complete at compile time, i.e., you could write a program using templates that didn't actually compile but would compute any result and display it somehow in the compilation error messages. He showed some pretty impressive computation examples -- none of which compiled but all produced the results as part of their error messages. Be careful what you wish for!

akhudek06:06:22

hah, templates are famous for that

munen12:06:38

I have a leiningen project with a file in the resources folder and would like to access a file inside it. My code works well in development mode, but not in the uberjar. I spent a couple hours scouring the Internet and am giving up now. I realise that directly accessing it with a relative path doesn’t work, because the path changes when the uberjar gets generated. Instead should be used. However in the uberjar this returns an URI, not a path. My current code looks like this, could someone please point me to a resource to get this to work(yeah, great pun^^):

(io/as-file (.getPath (io/resource "img/logo.png")))
I could slurp the path returned, however, the framework I’m using wants to have a File. Btw, the file actually is bundled in the jar, I checked^^

danlebrero13:06:05

You cannot create a java.io.File that points to a file inside the uberjar

danlebrero13:06:44

you will need to either not use java.io.File or copy the file from the uberjar to a temp folder

munen13:06:09

@danlebrero: The latter was my only solution. Now I know that it’s the right one. Thank you very much, the help and peace of mind is much appreciated!

jasonjckn21:06:44

how do I construct data literal #uuid "4cb5fd0b-c362-4785-bdbc-4c8707f52dea" programatically given a string

jasonjckn21:06:06

i tried (data-literal 'uuid "4cb5fd0b-c362-4785-bdbc-4c8707f52dea") but no luck

jasonjckn21:06:44

i basically want to call the parser on UUID

roberto21:06:54

what do you mean by a data literal?

jasonjckn21:06:21

i'm trying to implement this function (defn generate-uuid [uuid-str] ...)

jasonjckn21:06:44

i tried that, it didn't work

jasonjckn21:06:49

(tagged-literal 'uuid "4cb5fd0b-c362-4785-bdbc-4c8707f52dea") right?

Alex Miller (Clojure team)21:06:24

You can use tagged-literal to create a TaggedLiteral instance

Alex Miller (Clojure team)21:06:54

But uuids are just java.util.UUID instances with a special print form

Alex Miller (Clojure team)21:06:04

So you could also just make one of those

Alex Miller (Clojure team)21:06:54

Why did tagged-literal not work ?

jasonjckn21:06:33

I don't know, when I pretty print the result it looks good, but it's not composing with om.next/from-history, perhaps there's something else going on

(defn from-history [uuid]
  (pprint (tagged-literal 'uuid uuid))
  (om.next/from-history
   (:reconciler @admin.core/app)
   (tagged-literal 'uuid uuid)))
outputs on the REPL
#uuid "4cb5fd0b-c362-4785-bdbc-4c8707f52dea"
null

jasonjckn21:06:08

of course

(om.next/from-history (:reconciler @admin.core/app)  #uuid "4cb5fd0b-c362-4785-bdbc-4c8707f52dea")
works a expected though (doesn't return NULL)

jasonjckn22:06:16

(defn from-history [uuid-str]
  (om.next/from-history
   (:reconciler @admin.core/app)
   (uuid uuid-str)))

ilukinov22:06:17

Hello to everyone, when calling (sh "ping" "-t 5" "http://google.com”) I get result after 5 second (I'm on mac, so -t is timeout), is there a way to get results line by line as they come in like in real shell?