Is still idiomatic the ant simulation code?

642 views
Skip to first unread message

JuanManuel Gimeno Illa

unread,
May 29, 2012, 7:46:36 AM5/29/12
to clo...@googlegroups.com
I'm preparing an informal presentation about clojure concurrency and my plan is use the ant colony demo. Given the amount of changes in clojure since the time that code was written I wonder if the code is still idiomatic or parts of it should be adapted to modern clojure.

Any ideas would be much appreciated.

Thanks,

Juan Manuel

Stuart Sierra

unread,
Jun 8, 2012, 1:44:16 PM6/8/12
to clo...@googlegroups.com
The ants demo is definitely dated. It's not terrible, but the code could use some polishing/simplifying using newer additions to the language.
-S

JuanManuel Gimeno Illa

unread,
Jun 9, 2012, 4:08:43 PM6/9/12
to clo...@googlegroups.com
Can you elaborate some suggestions?

Juan Manuel

Alexey Kachayev

unread,
Jun 10, 2012, 1:00:15 PM6/10/12
to clo...@googlegroups.com
Guys, can you please share link where I can find the "ants demo" code?

-- 
Alexey Kachayev,
CTO at KitApp, Inc.

On Friday, June 8, 2012 at 4:44 PM, Stuart Sierra wrote:

The ants demo is definitely dated. It's not terrible, but the code could use some polishing/simplifying using newer additions to the language.
-S

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Curtis Gagliardi

unread,
Jun 11, 2012, 7:23:59 PM6/11/12
to Clojure
Here's the video: http://blip.tv/clojure/clojure-concurrency-819147
and you can get the code here (ants.clj):
http://www.lisptoronto.org/past-meetings/2009-05-clojure-ants-demo
or here if you don't want to download it: https://www.refheap.com/paste/3096

On Jun 10, 8:00 am, Alexey Kachayev <kacha...@gmail.com> wrote:
> Guys, can you please share link where I can find the "ants demo" code?
>
> --
> Alexey Kachayev,
> CTO at KitApp, Inc.
>
>
>
>
>
>
>
> On Friday, June 8, 2012 at 4:44 PM, Stuart Sierra wrote:
> > The ants demo is definitely dated. It's not terrible, but the code could use some polishing/simplifying using newer additions to the language.
> > -S
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clo...@googlegroups.com (mailto:clo...@googlegroups.com)
> > Note that posts from new members are moderated - please be patient with your first post.
> > To unsubscribe from this group, send email to
> > clojure+u...@googlegroups.com (mailto:clojure+u...@googlegroups.com)

Baishampayan Ghose

unread,
Jun 12, 2012, 5:59:12 AM6/12/12
to clo...@googlegroups.com
> Can you elaborate some suggestions?

I have updated the Ants sim code to use the "idiomatic" JVM inter-op
constructs and made some other minor changes.

Will work fine on Clojure 1.4

Here is the updated code - https://www.refheap.com/paste/3099
This is the unified diff - https://www.refheap.com/paste/3100

Needless to say, all mistakes are mine.

Regards,
BG

--
Baishampayan Ghose
b.ghose at gmail.com

Yann Schwartz

unread,
Jun 12, 2012, 8:07:23 AM6/12/12
to clo...@googlegroups.com
That's great. I've also noticed the sample still uses defstruct which is made obsolete by defrecord.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com

Baishampayan Ghose

unread,
Jun 12, 2012, 8:24:31 AM6/12/12
to clo...@googlegroups.com
On Tue, Jun 12, 2012 at 1:37 PM, Yann Schwartz <abolib...@gmail.com> wrote:
> That's great. I've also noticed the sample still uses defstruct which is
> made obsolete by defrecord.

While I agree that one could use a record in place of a struct, I
don't think structs are "obsolete", at least not officially.

Meikel Brandmeyer (kotarak)

unread,
Jun 12, 2012, 10:35:29 AM6/12/12
to clo...@googlegroups.com
Hi,


Am Dienstag, 12. Juni 2012 10:24:31 UTC+2 schrieb Baishampayan Ghose:

While I agree that one could use a record in place of a struct, I
don't think structs are "obsolete", at least not officially.


From http://clojure.org/datatypes:

Overall, records will be better than structmaps for all information-bearing purposes, and you should move such structmaps to defrecord.

Kind regards
Meikel
 

Baishampayan Ghose

unread,
Jun 12, 2012, 11:19:22 AM6/12/12
to clo...@googlegroups.com
>> While I agree that one could use a record in place of a struct, I
>> don't think structs are "obsolete", at least not officially.
>>
>
> From http://clojure.org/datatypes:
>
>>> Overall, records will be better than structmaps for all
>>> information-bearing purposes, and you should move such structmaps to
>>> defrecord.

In that case, defstruct, etc. should bear the same warning in
docstrings/metadata as well.

Yu Shen

unread,
Jul 28, 2014, 4:46:32 AM7/28/14
to clo...@googlegroups.com
What's the meaning of the following code:
 (([move #(turn % -1) #(turn % 1)]
               (wrand [(if (:ant @ahead) 0 (ranks ahead))
                       (ranks ahead-left) (ranks ahead-right)]))
            loc)))

in https://www.refheap.com/paste/3099  from line 192 to 195?

Sorry to bother you, it's new to me, and it's really hard to Google, as the characteristic of the code is not well defined. I'm learning Clojure in ad-hoc manner, so I might not be aware some Clojure expression. Giving me some pointer to study further would be sufficient. 

By the context, it seems that it's trying to take a move.

Thanks a lot!

Yu

Gary Johnson

unread,
Jul 29, 2014, 12:01:50 AM7/29/14
to clo...@googlegroups.com
Hi Yu,

  This is a pretty dense (and IMHO non-idiomatic) piece of Clojure code. Without reading the paste you provided, I can at least tell you what appears to be happening here, given Clojure's evaluation semantics:

1. The [move ...] expression creates a vector of three functions.
2. The [(if ...)] expression creates a vector of three values (presumably numeric) resulting from calls to the ranks function.
3. The (wrand ...) form calls wrand on the ranks vector to presumably produce an integer index into the [move ...] vector.
4. The [move ...] vector is called on wrand's result, which should return one of the three functions it contains.
5. The function returned from step 4 is called on loc.

  Happy hacking,
    ~Gary

Yu Shen

unread,
Jul 29, 2014, 4:54:16 AM7/29/14
to clo...@googlegroups.com
Hi Gary, 

Your examination makes perfect sense in the context. 

Thanks for your help!

Yu


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/sHLQN8m60qM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages