Fork me on GitHub
#clojure
<
2015-12-03
>
meow03:12:48

@rantingbob: I have clojure code modifying a polygon mesh using the http://thi.ng library output to an X3D file that I'm uploading to my Shapeways account where they render the file, which I'm simply saving as a jpg file. You can view/manipulate the model using the Shapeways 3D tools here: https://www.shapeways.com/model/3dtools/4108313/1/26?key=693ebbbc85d333d8708ec57a96dff6e2

rantingbob03:12:13

Thats really cool, thank you

meow03:12:21

Glad you like it. I'm having a lot of fun making them. You can see a bunch of them on my profile page on Shapeways here: https://www.shapeways.com/designer/pkobrien

meow03:12:34

Wow, that link came with a pretty spammy description. Wish it didn't do that.

meow03:12:46

Anyhow, it'll be fun to see some of these actually printed.

meow03:12:43

All my code is on github here: https://github.com/pkobrien/cad

meow03:12:07

Might have to change that description since I'm not really using OpenSCAD anymore as I can do more by manipulating a mesh directly in Clojure and outputting to X3D.

meow03:12:40

Here's one in silver. Don't ask what it would cost to actually print it. simple_smile https://images3.sw-cdn.net/model/picture/625x465_4093153_13239119_1449113030.jpg

rantingbob03:12:43

How well do they print out?

meow03:12:08

@rantingbob: I have no idea. I haven't gotten any of them printed yet. None of them are actually for sale. I'm still working on my process. These are just baby steps.

rantingbob04:12:29

@meow: What's the end goal, or is it just for fun?

meow04:12:24

Sell a lot of these, have fun, buy an island.

rantingbob05:12:26

That gold one is beautiful

devn06:12:45

@meow: that's really cool!

roelof07:12:22

Im trying to find out where this error message is coming from : CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long, of this code : https://www.refheap.com/112295. Anyone who can give me a hint where the problem is

andy.fingerhut07:12:12

@roelof: apply's last arg should be a sequence.

roelof07:12:09

you mean args ?

roelof07:12:40

@andy.fingerhut: thanks, I deleted apply and everything seems to work fine

roelof07:12:14

any remarks : https://www.refheap.com/112297 from the experts

andy.fingerhut07:12:52

@roelof: A minor comment is that if you wanted to change your code to allow a variable number of args as the name 'args' implies, you could put the 'apply' back in, and change process-user-action args to [action & args]

henriklundahl07:12:07

...or call it like (process-user-action :deposit [200]).

roelof07:12:24

args is only 1 number

roelof07:12:00

it's meant as very simple accounting system

henriklundahl07:12:06

The body of the deposit function could be changed to (update amount :amount + deposit-amount).

roelof07:12:14

@henriklundahl: oke, I Always thought that only swap could change the contents of a stom

roelof07:12:37

stom = atom

roelof07:12:08

@andy.fingerhut: as I meant it args can only be 1 number

henriklundahl07:12:39

Well, the update function doesn't really change anything. The code I proposed does exactly what your function does.

roelof07:12:04

oke, I did wonder if my function is then still pure

roelof07:12:35

and I did not know update as function exist. The clojure programming book makes no mention of it

roelof07:12:06

but then I could also change the body of the withdraw function to do the same

henriklundahl07:12:27

I believe it was added in Clojure 1.7.0. Before that there was update-in.

roelof07:12:16

oke, thanks , I like update more because it more clear what is does then swap

henriklundahl07:12:39

(update-in amount [:amount] + deposit-amount)

roelof07:12:03

thanks, Learned more and more

henriklundahl07:12:35

swap! is something else. It's for changing atoms. update and update-in just returns a new map.

roelof08:12:23

sorry. I was confused. you are right

roelof08:12:34

the swap is in another function

henriklundahl08:12:36

So you need swap! in process-user-action, but not in deposit or withdraw.

roelof08:12:33

as I said earlier. you are right. Think It's here to early

roelof08:12:07

Now I can think of how I make it work that the atom is updated and a description is added

roelof08:12:20

So I can make a sort of report of the account

roelof08:12:42

I think I need to "update" a seperate map for that

roelof08:12:17

or is there a better way ?

snowell13:12:25

Thanks for bringing update to my attention, @henriklundahl. I always hated my solution of (update-in coll [:one-key] f) 😄

Alex Miller (Clojure team)14:12:48

@arohner: replying to yesterday's question: yes, clojure core is AOT compiled with direct linking on (since 1.8.0-alpha3)

clark15:12:50

does anyone have a link handy where I'd be able to read about the work that's going into 1.8?

clark15:12:58

just curious about what's coming simple_smile

matt16:12:38

there's release notes linked from that page too that might be a better summary

clark16:12:02

@matt @birdspider awesome, thank you!

clark16:12:23

Looks like lots of perf improvements. Always welcome.

meow17:12:33

My first polygon mesh model is now available here: http://shpws.me/L0c3

marvotron17:12:59

i'll take a platinum one for review, i'll write something nice I promise 😛

marvotron17:12:38

jokes aside your work does look amazing

clark17:12:18

@alexmiller: perfect, thank you!

roelof17:12:21

If I use atom for a very simple accounting app. Schould I store the transitions into a map

roelof17:12:01

later I will try to put everything in a database

roelof18:12:42

@ajmagnifico: no problem. Can happen

exupero18:12:28

@ajmagnifico: You can delete messages.

ajmagnifico18:12:21

such amazing technology! simple_smile

roelof18:12:33

nobody who wants and can think with me if my solution is a good one ?

jeff.engebretsen18:12:27

@roelof I'd use a vector. Unless a time stamp is your map key.

roelof18:12:28

later on I wil try to put a date into the transaction

roelof18:12:44

I have this in my mind at the moment { :date 01-02-2015 :description "taken from the bank" :amount 100 :transaction-sort: "withdraw}

jeff.engebretsen18:12:40

Seems fine. I'd probably do -100. Then you could sum the amounts in order to see a balance at a given point.

roelof18:12:30

oke, but a I can image that a user finds -100 confusing

roelof18:12:04

So then I have to find out how I can put a date into the map

roelof18:12:24

Otherwise it will be a string

cfleming19:12:05

@meow: Are they Catmull-Clark subdivision surfaces?

meow19:12:04

@cfleming: that one starts as a hexahedron, then conway kis'd, then catmull-clark three times, then another conway kis, then colorized by the face normal

cfleming19:12:12

Nice, subdivs are like magic

meow19:12:24

the fun for me is to take these known algorithms, expose all of their parameters (or take a callback function that can do whatever the heck it wants) and then run through strange combinations of values and out come unexpected results - many are ugly, over time I can usually get it to settle on something that I like

meow19:12:33

catmull-clark is really nice, but also a bit heavy-handed - 3 seems to be the magic number before it just produces something indistinguishably smoother or a sphere

meow19:12:15

but I'm also intrigued with low-poly objects and using color to play tricks

robert-stuttaford19:12:47

yeah. i remember being utterly floored by the demo scene back before we had GUI OSes

robert-stuttaford19:12:21

the amazing amount of things they could pack into a meg or two, considering there were ZERO frameworks or anything. a great example of embracing constraints for creativity

meow19:12:16

so I recently came up with a different algorithm that maintains the bounding box of the original shape and doesn't move so much towards a sphere and it creates some really intriguing results - plus the parameters make a big difference so I can, for example, run it three times but each time with different parameters to get really controlled results within its basic mode of operation

meow19:12:33

I've rewritten the catmull-clark one time already from the version that comes with http://thi.ng and I'm about to rewrite it again and make it parameterized so I can mess with how it works

meow19:12:01

Yeah, just yesterday I rendered all my designs on shapeways in different materials so that you can see how the shapes look without color and how the color is really adding more depth and interest than actually exists in the basic topology.

robert-stuttaford19:12:26

i love the normals-decides-colour trick

meow19:12:04

there are so many directions I want to go with coloring and I just have to keep putting that off to work on the mesh operators for now

meow19:12:36

the color is just a function that gets passed the mesh and the face, so the sky is the limit on how the color is determined

meow19:12:03

I have one version the blends the color based on the face's neighbors -like cellular automata life rules

robert-stuttaford19:12:21

distance from camera, distance from mouse, combination of the two, etc

meow19:12:42

but it could use the distance from the centroid of the mesh, or distance from anything or averages or whatever

meow19:12:08

I do nothing with camera or mouse

meow19:12:42

I'm applying the color to the face of the polygon - how it gets rendered is done on Shapeway's servers.

meow19:12:08

I'm doing as little as possible to get the 2D rendering

meow19:12:56

Their rendering is supposed to simulate the materials they have available via their 3D printing service.

meow19:12:26

These are meant to be printed objects. I'm conforming to all their printing restrictions.

robert-stuttaford19:12:37

i’d love to see a material that changes colours based on ‘normals’ simple_smile

robert-stuttaford19:12:49

that’s awesome, though. you planning to have some printed?

meow19:12:13

I'm planning to have other people buy them. 😉

robert-stuttaford19:12:47

made with maths and lisp and love

meow19:12:56

By the time I upload them to Shapeways I'm kinda tired of looking at them... 😉

meow19:12:21

and the dozens of variations that get discarded along the way

meow19:12:27

Actually, its kinda hard to stop spinning them around and zooming in and out. It's addicting.

meow19:12:09

I want to make virtual reality worlds out of this stuff as well.

pvinis19:12:12

in (def columns# 9) what does # mean?

robert-stuttaford19:12:55

nothing. think of it as the 27th character of the alphabet simple_smile

pvinis20:12:14

just in the name then?

pvinis20:12:36

so if i need to use that, i would just put columns# normally..

ghadi20:12:17

pvinis: in the context of a macro unsplice

`(let [foo#  ....])
ending with a # has a specific meaning (auto-generated symbol), but outside the unsplice it doesn't

pvinis20:12:36

cool. thanks

lvh20:12:40

I was kind of expecting flatten to get me a transducer

lvh20:12:48

What do I do instead? (mapcat identity)?

meow20:12:00

maybe cat

meow20:12:39

its a transducer

lvh20:12:46

oh, right; I guess cat is what I want simple_smile

lvh20:12:57

(well, cat doesn’t flatten all the way, but I don’t need that)

meow20:12:58

new in 1.7

roelof20:12:54

@jaen: thanks, I will look and play with it

pvinis20:12:02

ok so im trying go model a card game, and wanna generate the deck. i have this (map (fn [n] (suit-card :hearts n)) (range 1 14)) which generates all hearts i tried to do this (map (fn [s] (map (fn [n] (suit-card s n)) (range 1 14)))) but i get a fn back so i guess map in map is a bit weird?

jeff.engebretsen21:12:07

Are you passing the suits to the outer map?

pvinis21:12:17

oh shit...

jeff.engebretsen21:12:42

Did that fix it?

pvinis21:12:10

i am not used to clojure yet, so i just closed all parens, without putting the suits there

mdaines21:12:58

If you want all the cards, you could also try a for comprehension.

jeff.engebretsen21:12:16

I'm confused why it returned a fn instead of throwing an Arity exception.

mdaines21:12:31

(for [rank (concat (range 1 11) [:jack :queen :king]) suit [:spade :club :diamond :heart]] [rank suit])

mdaines21:12:46

The function is because it is returning a transducer.

jeff.engebretsen21:12:32

You can do nested for's that way?!

tesseract21:12:47

hi all, is there anyway on the CLI to get a list of all possible flags for new project? (luminus in my case)

pvinis21:12:01

mdaines: i thought of that, but that gives me a vector

pvinis21:12:25

vector of vectors. and for me, each card is a map

pvinis21:12:32

can i do that with for?

mdaines21:12:56

Yeah. The very last part [rank suit] determines what will be returned.

noonian21:12:12

{:rank rank, :suit suit} would return a sequence of maps

pvinis21:12:34

ok it worked now.. something before didnt work

pvinis21:12:51

so i thought for coould only return vectors inside

pvinis21:12:05

alright, for is better. ill do it like that

pvinis21:12:24

out of curiosity, is there a specific order for works?

pvinis21:12:19

does it go always likg for first { for second { for third { bla }}}?

mdaines21:12:23

Collections are iterated in a nested fashion, rightmost fastest,
   and nested coll-exprs can refer to bindings created in prior
   binding-forms.

mdaines21:12:48

So, yeah, kinda like you said.

mdaines21:12:11

np. And if you are just getting started, make sure you know about shuffle for handling a card game.

pvinis21:12:34

ok and now for a bit of testing. i have a vec of hands i wanna test. how can i test all of them together? so instead of 10 (is (single? hand1)), can i have something like a map to that?

timgilbert23:12:28

pvinis, you could maybe use (doseq) for that, which is similar to (for) but just executes its body for side effects (like is)

pvinis23:12:43

i was just looking at that

timgilbert23:12:00

So like (doseq [hand all-hands] (is (single? hand)))

pvinis23:12:10

im also using the -> now..

pvinis23:12:19

bbut im sure my code is ugly

timgilbert23:12:05

Another approach would be (map (fn [h] (is (single? h)) all-hands)

timgilbert23:12:39

Or (map #(is (single? %)) all-hands)

timgilbert23:12:17

Personally I like doseq for that kind of thing because it gives me a heads-up to look for side effects

pvinis23:12:35

oh, can i do map for testing?

pvinis23:12:50

what do you think about this code..

timgilbert23:12:59

One thing is you can simplify (map (fn [card] (:rank card)) trick) to (map :rank trick) which is a little easier to read

pvinis23:12:20

forgot that keys are also funcs, even though i actually used it..

pvinis23:12:47

better this way, right?

timgilbert23:12:00

I'm not sure that function does what you intend it to do either, if I'm reading right after (set) you'd have #{ 4 }

timgilbert23:12:22

I like that ok

pvinis23:12:38

i want to check that we have 3 card of the same rank

pvinis23:12:03

so i thought, check the number of cards, and take all the ranks and see if its the same for all

pvinis23:12:20

so i thought, make it a set. if its just one number in the set, its fine

timgilbert23:12:25

I think that works if you only ever have 3 cards, but it would also return true for 7 cards

pvinis23:12:50

no, because of the (= (count trick) 3)

timgilbert23:12:06

Oh, I see, right

timgilbert23:12:12

Sorry, missed that bit

pvinis23:12:27

thats the whole thing again

pvinis23:12:37

you scared me 😛

pvinis23:12:36

is there some kind of counted set in clojure?

pvinis23:12:54

or should i just use a sorted vector or something?

pvinis23:12:41

ah. frequencies

pvinis23:12:36

i want to chck if numbers in a seq are continious, is that close? (reduce (fn [a b] (= (inc a) b)) (list 4 5 6))

pvinis23:12:57

so 4 5 6 would give true, and 4 5 7 would give false

jaredly23:12:30

pvinis: reduce won't do

pvinis23:12:49

how could i do that?

meow23:12:20

Is there a generalization of this pattern I find myself repeating a lot:

(into {} (for [item coll] [item (somefunc item)]))

jaredly23:12:39

@pvinis: lemme see, I'm a bit new to the particular function names

jaredly23:12:09

pkobrien: map won't do? edit: oh wait I see

meow23:12:40

I need the result to be a map

meow23:12:04

was going to code something like (defn into-map [coll f] (into {} (for [item coll] [item (f item)])))

jaredly23:12:07

maybe (zipmap coll (map coll somefunc))

meow23:12:02

yeah, zipmap might be the ticket

jaredly23:12:19

rather (zipmap coll (map somefunc coll))

meow23:12:32

yeah, I knew what you meant simple_smile

meow23:12:14

still more verbose than if I write the func I wrote above

pvinis23:12:08

could i maybe use doseq for my check?

meow23:12:59

I'm using this pattern a lot and want to reduce bloat.

ajmorgan23:12:23

pvinis: are you looking for something like (= coll (sort coll))

jaredly23:12:39

@pvinis: I'm thinking something like (every? (fn [[a b]] (= (inc a) b)) (partition 2 1 [1 2 3]))

pvinis23:12:24

ajmorgan: no, i need them to be +1 for every next number

pvinis23:12:44

jaredly: didnt know every? let me try