Re: clj-soap (was: Beginner question

2015-08-06 Thread blake watson
We did some soap as well, and found the same thing, except in our case,
SOAP was merely a formality. In other words, it seems some people are using
only the barest of SOAP features, and wrapping up the meat up in a SOAP
envelope.

In other words, we were able to just generate a skeleton in Soap-UI and
then parse out the contents with clojure.xml/parse.

On Thu, Jul 30, 2015 at 3:36 PM, Sean Corfield  wrote:

> On Jul 29, 2015, at 7:47 PM, Mike  wrote:
>
> I have done some searching, and there is an old clj-soap library which
> Sean Corfield has mostly abandoned.
>
>
> Just to clarify: I too had started down the path of trying to find a way
> to do SOAP via Clojure and came across the old and *already abandoned*
> clj-soap library so I forked it and got it "working" with Clojure 1.3.0
> (since it was built for 1.2.0) and whilst I could get a few basic SOAP
> services working with it, nothing complex actually worked at all.
>
> At that point I tried a different approach using wsdl2java, compiling the
> generated Java, and then calling that directly and using the Axis libraries
> via Java interop from Clojure. That worked for the complex SOAP service I
> needed and took a lot less time than figuring our how to make clj-soap work
> generically.
>
> As it says on the repo:
>
> I forked it purely to get it running on Clojure 1.3 and then found it
> didn't do what I needed anyway.
>
> If you think it might be useful to you, please fork it and maintain it
> yourself. If you decide to take over as lead maintainer, let me know and
> I'll update this readme to point to your new fork.
>
> Sean Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


clj-soap (was: Beginner question

2015-07-30 Thread Sean Corfield
On Jul 29, 2015, at 7:47 PM, Mike  wrote:
> I have done some searching, and there is an old clj-soap library which Sean 
> Corfield has mostly abandoned.

Just to clarify: I too had started down the path of trying to find a way to do 
SOAP via Clojure and came across the old and already abandoned clj-soap library 
so I forked it and got it "working" with Clojure 1.3.0 (since it was built for 
1.2.0) and whilst I could get a few basic SOAP services working with it, 
nothing complex actually worked at all.

At that point I tried a different approach using wsdl2java, compiling the 
generated Java, and then calling that directly and using the Axis libraries via 
Java interop from Clojure. That worked for the complex SOAP service I needed 
and took a lot less time than figuring our how to make clj-soap work 
generically.

As it says on the repo:

I forked it purely to get it running on Clojure 1.3 and then found it didn't do 
what I needed anyway.

If you think it might be useful to you, please fork it and maintain it 
yourself. If you decide to take over as lead maintainer, let me know and I'll 
update this readme to point to your new fork.


Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Beginner question

2015-07-29 Thread Francis Avila
Note: my knowledge of soap is not very deep, but I have done the following 
in a production system.

If you have a WSDL available, a good approach is to generate the (Java) 
client code and then use it via Java interop.  You can smooth out the rough 
edges and shed the extra java types by using the clojure.java.data library 
to define to-java and from-java 
methods. https://github.com/clojure/java.data


The state-of-the-art in java code generation from a WSDL seems to be Apache 
cxf http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html 
 Below is a mini-tutorial of its use.

In the project.clj, add the configuration and dependencies that cxf needs. 
We'll be using cxf through a maven plugin that wraps it 
(cxf-codegen-plugin).  The maven plugin
is configured via a pom, so we'll use leinigen's :pom-additions and 
:pom-plugins keys to inject stuff into the pom it generates.


(defproject my-soap-client "0.0.1-SNAPSHOT"
  :description "Example of using leinigen to generate a pom to generate Java 
from WSDLs using maven and cxf-codegen-plugin"

  :source-paths [] ;; NOTE: No Clojure code!
  :java-source-paths ["src"] ;; NOTE: Where the *generated* java will go!
  ;; NOTE: Adding source path to clean targets because it is generated code!
  :clean-targets ^{:protect false} [:target-path :compile-path 
:java-source-paths]

  :pom-addition [:properties [:project.build.sourceEncoding "UTF-8"]]

;; This is all Maven stuff, documented here: 
https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Configuring_Build_Plugins
;; What you see below is serialized as XML in the generated pom.xml
  :pom-plugins
  [[org.apache.maven.plugins/maven-source-plugin "2.4"
{:executions
 [:execution
  [:id "bundle-sources"]
  [:goals
   [:goal "jar-no-fork"]]]}]
   [org.apache.cxf/cxf-codegen-plugin "3.1.1"
{:executions
 [:execution
  [:id "my-execution-id"]
  [:phase "generate-sources"]
  [:configuration
   [:sourceRoot "${project.basedir}/src"]
;; NOTE: Options documented here: http://cxf.apache.org/docs/wsdl-to-java.html
;; Some WSDLs may need more or fewer options than shown here.
   [:wsdlOptions
[:wsdlOption
;; NOTE: Consider downloading the wsdl to a file.
 [:wsdl "https://example.org/mywsdl";]
 [:extraargs
  [:extraarg "-verbose"]
  [:extraarg "-mark-generated"]
  [:extraarg "-exsh"] [:extraarg "true"]
  [:extraarg "-autoNameResolution"]
  [:goals [:goal "wsdl2java"]]]}]])



Then with this project.clj in place, you build your java code like so:

#!/bin/sh

lein do clean, pom && mvn package

# This will define variables used below.
source target/maven-archiver/pom.properties

BUILT_JAR=target/${artifactId}-${version}.jar
SRC_JAR=target/${artifactId}-${version}-sources.jar

# You can then use the "full" form of lein deploy to create a maven-compatible 
release artifact
# Include this in your *real* clojure project as a dependency!
# TODO: I don't know how (or if it is possible) to get leinigen to deploy 
separate
# java/maven source or javadoc jars too.

lein deploy releases "${groupId}/${artifactId}" "${version}" "${BUILT_JAR}" 
pom.xml



Up until now we have done nothing that really involves Clojure. This could 
have been a plain Java maven project with a handcrafted pom.xml. The jar 
itself is just compiled java class files. I just used leinigen because it 
was more familiar.


In your actual Clojure project, require this java-soap-client project you 
deployed:

[my-soap-client "0.0.1-SNAPSHOT"]

Then use it via Java interop. Details may vary (see your WSDL or the SOAP 
service documentation), but usually there's a Service object you need to 
instantiate somehow, and then call getSoapXX on it to get a Port object 
which has methods on it corresponding to the SOAP methods the service 
provides.  I think both of these are stateless and long-lived and can be 
shared by threads.

(import '(my.soap.service ServiceClass))

(let [service (ServiceClass.)
  port(.getSoap12 service)]

;; Sometimes the WSDL does not include the url of the soap service and you 
have to set it manually
(import '(javax.xml.ws BindingProvider))

  (.. ^BindingProvider port (getRequestContext) (put 
BindingProvider/ENDPOINT_ADDRESS_PROPERTY endpoint))


  ;; Now call your SOAP methods!
  (.mySoapMethod port)

)


Depending on the SOAP service and its WSDL, probably have a huge jumble of 
Java types to deal with in requests and responses, and you may even have 
raw XML to contend with, too. Your life will be much easier if you 
immediately convert instances from the Java client into plain Clojure data 
structures, and convert those data structures into the proper types right 
before you call the SOAP methods. clojure.data.java makes doing this much 
easier: you define a to-java and a from-java multimethod for the SOAP types 
you care about. It is also generic enough to handle many Java-bean like 
objects autom

Beginner question

2015-07-29 Thread Mike
Hello,

I have decided what my first Clojure project will be, but I could use some 
guidiance.  I would like to be able to make SOAP calls to a webservice on 
another machine.

I have done some searching, and there is an old clj-soap library which Sean 
Corfield has mostly abandoned.  How are people doing this?  WOuld someone 
be so kind as to post a small example?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Caribou Data Modeling - Beginner question

2014-01-29 Thread Leon Talbot
Ok I got it. 

Supporters, Actions and Questions needs to be created separately and linked 
to Idea. (Idea, which is created at first, doesn't need to mention those)

Makes sense!

 

> When I log in to the admin and try to "Modify" this new model, I get only 
> to see the first 3 custom fields (Title, Desc and Supporters)
>
> Why is that so? What am I doing wrong?
>
> Thanks very much!
>
> Leon, a clojure beginner 
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Caribou Data Modeling - Beginner question

2014-01-28 Thread Leon Talbot
I open an REPL (lein repl) and add a model by pasting this :

(caribou.core/with-caribou (boot/boot)
  (caribou.model/create 
   :model
   {:name "Idea"
:fields [{:name "Title" :type "string"}
 {:name "Desc" :type "string"}
 {:name "Supporters" :type "link"}
 {:name "Actions" :type "link"}
 {:name "Questions" :type "collection"}]}))

When I log in to the admin and try to "Modify" this new model, I get only 
to see the first 3 custom fields (Title, Desc and Supporters)

Why is that so? What am I doing wrong?

Thanks very much!

Leon, a clojure beginner 

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: beginner question

2011-09-25 Thread Andy Fingerhut
All persistent data structures are immutable, but not all immutable data
structures are persistent.

For example, imagine an immutable array that, unlike Clojure's vector data
structure, implemented "conj" by copying the entire array into a new one
with the original elements plus the new one.  Immutable, but the performance
characteristics are abysmal.

As a more subtle example, imagine an immutable array that, unlike Clojure's
vector data structure, let you "update" arbitrary elements, and did not copy
the entire array, but created an imbalanced tree of vector indices that had
their values "updated".  A lookup in this augmented data structure would
require first looking through the imbalanced tree for the index, to see if
it had been modified, and only if it failed to find it in the tree would it
be looked up in the original array.  Immutable, but not persistent in the
sense that it maintains the performance characteristics of the original data
structure -- the augmented/updated data structure has slow access times than
the original.

Andy

On Sun, Sep 25, 2011 at 11:34 AM, Dennis Haupt wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> so there is no difference.
>
> Am 25.09.2011 15:28, schrieb Stuart Halloway:
> >> what's the difference between persistent and immutable?
> >
> > See http://en.wikipedia.org/wiki/Persistent_data_structure, which
> > now has a nice shout out to Clojure.
> >
> > Stu
> >
>
>
> - --
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.14 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQIcBAEBAgAGBQJOf3QyAAoJENRtux+h35aGsKQP/jHBNqhUCQfSQ7XjCe3vTlF5
> zhjcXmyhWbRUF7fEsrmljtpOu630gAnl51cmlBOwpOQXLmGJg386422GzUtRexG3
> A4KcrYEahAKBK5R1Tiu3WMqAr/h3t9oYi6APYaU29qJqqO6lnZR/bp1yAR+wnmZT
> ausVGzUlE+p5DlfWHAMaAsEVYp1XX282BKecgr/cHsBy9Jwl2NdWQl0Ss/ZYPj7x
> JE04/y6T/1jomWdM+dwXZ/oCucWmDjSgg3nHMUy/P9yab0kN2qHprqomBCBQeOpj
> zY5KS2/0x6nS9XpNfKF1f7VdqG8RkVdE+iE14a5uzCWzAQfMbeZUQcyOv8H8QQXU
> v0VYO1htvWwoJRqoCUan5UhrucM+LDqFEml7n8S4y7kbWWy9CJHD0bq9VjgIBIJY
> oo8VrFM7ciO+9mmJ7VfdNmUKPmcclWVFp3PVbNKJVMFXO7s+Myj5y/irWDJ3fBTY
> VYiCKNtbU9uaNZRVfyTQhVF5i+607BfH78S6wA1fEXYWWcvNiwEBoTaKi4cHh6wF
> nbaVf2xOLahJngEg6m8yBQfcnRm5H6WZ2h53UA+c1AgwiRgOAt+FGiK6J695EZbp
> LlslJGUH9QVZXsDVWPthtr2Qk8fJtT7c7UQksfYU+F8lANtyTMcN/kAQ2ngZ2pbq
> aLOthkidIm51E9NkBRH5
> =SNNL
> -END PGP SIGNATURE-
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: beginner question

2011-09-25 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

so persistent is immutable + x like "car" is "movable" + x. it doesn't
make sense to ask what the difference is.

Am 25.09.2011 18:59, schrieb Phil Hagelberg:
> 
> On Sep 25, 2011 6:12 AM, "Dennis Haupt"  > wrote:
>> what's the difference between persistent and immutable?
> 
> I have written a summary of this distinction on my blog: 
> http://technomancy.us/132
> 
> Hope that helps.
> 
> -Phil
> 
> -- You received this message because you are subscribed to the
> Google Groups "Clojure" group. To post to this group, send email to
> clojure@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+unsubscr...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/clojure?hl=en


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOf3/bAAoJENRtux+h35aGFrIQAJCTY0ZVAQ1LHda9tIkiV/am
hi/bSleO4qFJceGUWuoDP8nrTIc6kDZrhNv7IIYeV59GzETYsEctfUIIosNEnS94
Oya6DpoOWLFlVwLsSVrIkFNbl5WEnEhoi7myO3zxuO0PksefmzLs57oC5ijw24PP
3CQrGiLpO1dI9s7bk8fBEuBDnC+d0GOZH4YAa3EYMp/1VQoRFLgBy3Occ1DVcqcZ
nTac2Gexru0vA9On1RW6d0xSNEPQk33gAnt5fU72LCTi9bAekEPb66y538LKElS4
0nc4x6rEI9ijOLxvTkariCPEIy3yGZ5NcQxZWI1XR1c6J5sD8rsB3d5HZTzsy2Ez
n4NnRXw/zrIxyqLWwoYaZyfqltJdoIvE2qf9d4zMmuj0JHlW518GF7M3aXigdImt
uuSqQkUJ4tadSb/UKWITqEN+F/UpaohNamnWLCbvgDl4MGJ2kGU46tC91Su4N79e
iPfZ3gcyNMuRuO2i2v31OTw86TOwxGhtAJEEDvL8MRIce038fpt+QVybHUsDiGzS
G9OczcysVZstfPphSzfUpMsUUUNSc5lmyskYBQV6xiqwC8VOE+bY/+ejlNm4nHQC
8Qdfqzq7sI7gXPg5yUUvc3xaT8RdT/X2FqL1B54g17pz44gDJW9LlvNXNwP0jTOm
cBFvQnI1tQZRvEcqbaTO
=C3n7
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-25 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

so there is no difference.

Am 25.09.2011 15:28, schrieb Stuart Halloway:
>> what's the difference between persistent and immutable?
> 
> See http://en.wikipedia.org/wiki/Persistent_data_structure, which
> now has a nice shout out to Clojure.
> 
> Stu
> 


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOf3QyAAoJENRtux+h35aGsKQP/jHBNqhUCQfSQ7XjCe3vTlF5
zhjcXmyhWbRUF7fEsrmljtpOu630gAnl51cmlBOwpOQXLmGJg386422GzUtRexG3
A4KcrYEahAKBK5R1Tiu3WMqAr/h3t9oYi6APYaU29qJqqO6lnZR/bp1yAR+wnmZT
ausVGzUlE+p5DlfWHAMaAsEVYp1XX282BKecgr/cHsBy9Jwl2NdWQl0Ss/ZYPj7x
JE04/y6T/1jomWdM+dwXZ/oCucWmDjSgg3nHMUy/P9yab0kN2qHprqomBCBQeOpj
zY5KS2/0x6nS9XpNfKF1f7VdqG8RkVdE+iE14a5uzCWzAQfMbeZUQcyOv8H8QQXU
v0VYO1htvWwoJRqoCUan5UhrucM+LDqFEml7n8S4y7kbWWy9CJHD0bq9VjgIBIJY
oo8VrFM7ciO+9mmJ7VfdNmUKPmcclWVFp3PVbNKJVMFXO7s+Myj5y/irWDJ3fBTY
VYiCKNtbU9uaNZRVfyTQhVF5i+607BfH78S6wA1fEXYWWcvNiwEBoTaKi4cHh6wF
nbaVf2xOLahJngEg6m8yBQfcnRm5H6WZ2h53UA+c1AgwiRgOAt+FGiK6J695EZbp
LlslJGUH9QVZXsDVWPthtr2Qk8fJtT7c7UQksfYU+F8lANtyTMcN/kAQ2ngZ2pbq
aLOthkidIm51E9NkBRH5
=SNNL
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-25 Thread Phil Hagelberg
On Sep 25, 2011 6:12 AM, "Dennis Haupt"  wrote:
> what's the difference between persistent and immutable?

I have written a summary of this distinction on my blog:
http://technomancy.us/132

Hope that helps.

-Phil

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: beginner question

2011-09-25 Thread Stuart Halloway
> what's the difference between persistent and immutable?

See http://en.wikipedia.org/wiki/Persistent_data_structure, which now has a 
nice shout out to Clojure.

Stu

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-25 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 25.09.2011 14:00, schrieb Stuart Halloway:
>> the website says:
>> 
>> deftype supports mutable fields, defrecord does not
>> 
>> so deftype seems to be what would be a java bean with simple 
>> properties in java
> 
> Nope. :-)
> 
> Domain information should use defrecord, and should never be
> mutable. This is the closest thing to a Java bean, but is radically
> different in being (1) immutable, (2) persistent, and (3)
> accessible generically as a map. Game state would modeled with
> defrecord.

what's the difference between persistent and immutable?

> 
> deftype is for things like custom data structures. In a
> Clojure-in-Clojure implementation, deftype would be used to
> implement maps, vectors, and lists. deftype's mutation ability
> would be used to implement transients.
> 
> Stu
> 
> 


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOfyimAAoJENRtux+h35aGtacQALmFsfHsPuCMt/QZM1gfwMNN
e3C0Q2Dju0GgG/PNGTyV25mWII0JGrvl5UK13VLb2q93bNW4l43SeS4glxE1USBd
Btbo1QwGiAkIffhSrcXLQT+2K4PM4b0fbLwkF41obAEVEf3JDpMjZ9Qjxbrz9D7v
WDH+JBx5rQxvk3ctPqtK59OCkH7fRtMM6bLuwHdFc9YhQt7VjmloaZaAmuXfL3+B
sq//dTOuUy94ZZSsERUWWYeqRIvL5gTVkT1QTbElVHCzixH25fnTX8G3b/04bmX6
ME2P/3iSsrYdHfO35caRwQfIm29JYkljwER1vyX0n4iotouodOyTxo4s4du5PZM1
G+xWrzw65ejn3Y6GaSOFjb02wJUhku2cHyXcjY+Xdb3RXNgtTBQurW5Jx+wCmGV5
Kj3GtharuM16n4weCS0aK5meNFFmu8Djn11+cWePyjQ9qVos1ei3f8s01bN13Qbv
p1qUh+5D4eJb39A4cETrJpINXIhXf2Ngg7tpyQQjzppT/iqtIVdKHMVFOiazHzh2
1aLFCBRGVoErCukB84fCmwZ9JJP8NiRzyw7choMbNeBREKhX9+WFJfwDZyygrezD
kTRa7F2iwz1gEfO3kP8vevdObmtQdQgAMxQ/4IG4xLtmptfL25U/5pgvvi9jOX5T
WYY70N5yr64Evgw6Bt9S
=y3Ge
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-25 Thread Stuart Halloway
> the website says:
> 
> deftype supports mutable fields, defrecord does not
> 
> so deftype seems to be what would be a java bean with simple
> properties in java

Nope. :-)

Domain information should use defrecord, and should never be mutable. This is 
the closest thing to a Java bean, but is radically different in being (1) 
immutable, (2) persistent, and (3) accessible generically as a map. Game state 
would modeled with defrecord.

deftype is for things like custom data structures. In a Clojure-in-Clojure 
implementation, deftype would be used to implement maps, vectors, and lists. 
deftype's mutation ability would be used to implement transients. 

Stu


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-25 Thread Stefan Kamphausen
Hi,

regarding the writing of a game in Clojure, I think 
http://codethat.wordpress.com/2011/09/10/writing-tetris-in-clojure/ is a 
good post to read.

Regards,
Stefan

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: beginner question

2011-09-24 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

the website says:

deftype supports mutable fields, defrecord does not

so deftype seems to be what would be a java bean with simple
properties in java

Am 24.09.2011 23:11, schrieb Matt Hoyt:
> Both of them are java objects.  Records has more default
> functionality like implementing equals, hashcode, etc.  You can
> read more about the differences here: http://clojure.org/datatypes
> 
> assoc for records sets the value of the property for the record.
> 
> Matt Hoyt 
> 
>
> 
*From:* Dennis Haupt 
> *To:* clojure@googlegroups.com *Sent:* Saturday, September 24, 2011
> 3:54 PM *Subject:* Re: beginner question
> 
> i assumed my game to be so much fun that no one would ever want to 
> stop playing it.
> 
> Am 24.09.2011 22:26, schrieb Matt Hoyt:
>> You need a check in the loop to see if the player wants to end
>> the game. Clojure doesn't have a break statement like Java so
>> you created a infinite loop that will never end.  To make sure
>> the game ends you need to have a base case.  Example of a main
>> game loop in clojure:
> 
>> (loop [game-state initial-state] (if (game-ends? game-state) 
>> (close-game game-state) (recur (render (logic game-state)
> 
>> You should also look into records to store the game's state. 
>> Records are faster than hash maps and you have polymorphism with 
>> protocols.
> 
> if i remember correctly, deftype = map, defrecord = class? how does
> "assoc" work on records?
> 
> 
> Be
>> careful of the lazy functions in clojure like map.  It will only 
>> execute when you ask a value for it.
> 
> render should do that
> 
> 
>> Matt Hoyt 
>> 
>
>> 
> 
> *From:* Dennis Haupt  <mailto:d.haup...@googlemail.com>>
>> *To:* clojure@googlegroups.com <mailto:clojure@googlegroups.com>
> *Sent:* Saturday, September 24, 2011
>> 2:36 PM *Subject:* beginner question
> 
>> in java, i would start coding a game with a loop like this:
>> while (true) { logic(); render(); }
> 
>> i would store the current state of the world in an object 
>> containing the complete data of the whole game and update its 
>> values in each iteration.
> 
>> how would i do this in clojure?
> 
>> the outer loop could look like (def next [oldstate] ()) <- 
>> input = current game, return value = next iteration
> 
>> (loop [world initalState] (recur (next world))) // <- the loop
> 
>> but how would be world look like? the "best" (most trivial)
>> thing that i could think of is for it to be a map which is passed
>> along several transform functions, for example
> 
>> (def playerHealthRegen [world] (...)) <- input = world (a map), 
>> output = a new map with a new entry at key "playerhealth"
> 
>> each function would then return a slightly modified version of
>> the world, and at the end, i'll have my completely new state.
> 
>> is that about right? or is there a completely different way i 
>> overlooked?
> 
> 
>> -- You received this message because you are subscribed to the 
>> Google Groups "Clojure" group. To post to this group, send email
>> to clojure@googlegroups.com <mailto:clojure@googlegroups.com>
> <mailto:clojure@googlegroups.com <mailto:clojure@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+unsubscr...@googlegroups.com
>> <mailto:unsubscr...@googlegroups.com> 
>> <mailto:unsubscr...@googlegroups.com
> <mailto:unsubscr...@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 the 
>> Google Groups "Clojure" group. To post to this group, send email
>> to clojure@googlegroups.com <mailto:clojure@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+unsubscr...@googlegroups.com
> <mailto:unsubscr...@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 the
> Google Groups "Clojure" group. To post to this group, send email 

Re: beginner question

2011-09-24 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

mutable? like in "not functional"?
*reading*

Am 24.09.2011 23:11, schrieb Matt Hoyt:
> Both of them are java objects.  Records has more default
> functionality like implementing equals, hashcode, etc.  You can
> read more about the differences here: http://clojure.org/datatypes
> 
> assoc for records sets the value of the property for the record.
> 
> Matt Hoyt 
> 
>
> 
*From:* Dennis Haupt 
> *To:* clojure@googlegroups.com *Sent:* Saturday, September 24, 2011
> 3:54 PM *Subject:* Re: beginner question
> 
> i assumed my game to be so much fun that no one would ever want to 
> stop playing it.
> 
> Am 24.09.2011 22:26, schrieb Matt Hoyt:
>> You need a check in the loop to see if the player wants to end
>> the game. Clojure doesn't have a break statement like Java so
>> you created a infinite loop that will never end.  To make sure
>> the game ends you need to have a base case.  Example of a main
>> game loop in clojure:
> 
>> (loop [game-state initial-state] (if (game-ends? game-state) 
>> (close-game game-state) (recur (render (logic game-state)
> 
>> You should also look into records to store the game's state. 
>> Records are faster than hash maps and you have polymorphism with 
>> protocols.
> 
> if i remember correctly, deftype = map, defrecord = class? how does
> "assoc" work on records?
> 
> 
> Be
>> careful of the lazy functions in clojure like map.  It will only 
>> execute when you ask a value for it.
> 
> render should do that
> 
> 
>> Matt Hoyt 
>> ----
>
>> 
> 
> *From:* Dennis Haupt  <mailto:d.haup...@googlemail.com>>
>> *To:* clojure@googlegroups.com <mailto:clojure@googlegroups.com>
> *Sent:* Saturday, September 24, 2011
>> 2:36 PM *Subject:* beginner question
> 
>> in java, i would start coding a game with a loop like this:
>> while (true) { logic(); render(); }
> 
>> i would store the current state of the world in an object 
>> containing the complete data of the whole game and update its 
>> values in each iteration.
> 
>> how would i do this in clojure?
> 
>> the outer loop could look like (def next [oldstate] ()) <- 
>> input = current game, return value = next iteration
> 
>> (loop [world initalState] (recur (next world))) // <- the loop
> 
>> but how would be world look like? the "best" (most trivial)
>> thing that i could think of is for it to be a map which is passed
>> along several transform functions, for example
> 
>> (def playerHealthRegen [world] (...)) <- input = world (a map), 
>> output = a new map with a new entry at key "playerhealth"
> 
>> each function would then return a slightly modified version of
>> the world, and at the end, i'll have my completely new state.
> 
>> is that about right? or is there a completely different way i 
>> overlooked?
> 
> 
>> -- You received this message because you are subscribed to the 
>> Google Groups "Clojure" group. To post to this group, send email
>> to clojure@googlegroups.com <mailto:clojure@googlegroups.com>
> <mailto:clojure@googlegroups.com <mailto:clojure@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+unsubscr...@googlegroups.com
>> <mailto:unsubscr...@googlegroups.com> 
>> <mailto:unsubscr...@googlegroups.com
> <mailto:unsubscr...@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 the 
>> Google Groups "Clojure" group. To post to this group, send email
>> to clojure@googlegroups.com <mailto:clojure@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+unsubscr...@googlegroups.com
> <mailto:unsubscr...@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 the
> Google Groups "Clojure" group. To post to this group, send email to
> clojure@googlegroups.com <mailto:clojure@googlegroups.com> Note
> that posts from 

Re: beginner question

2011-09-24 Thread Matt Hoyt
Both of them are java objects.  Records has more default functionality like 
implementing equals, hashcode, etc.  You can read more about the differences 
here: http://clojure.org/datatypes

assoc for records sets the value of the property for the record. 

Matt Hoyt



From: Dennis Haupt 
To: clojure@googlegroups.com
Sent: Saturday, September 24, 2011 3:54 PM
Subject: Re: beginner question

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

i assumed my game to be so much fun that no one would ever want to
stop playing it.

Am 24.09.2011 22:26, schrieb Matt Hoyt:
> You need a check in the loop to see if the player wants to end the
> game. Clojure doesn't have a break statement like Java so you
> created a infinite loop that will never end.  To make sure the game
> ends you need to have a base case.  Example of a main game loop in
> clojure:
> 
> (loop [game-state initial-state] (if (game-ends? game-state) 
> (close-game game-state) (recur (render (logic game-state)
> 
> You should also look into records to store the game's state.
> Records are faster than hash maps and you have polymorphism with
> protocols.

if i remember correctly, deftype = map, defrecord = class?
how does "assoc" work on records?


Be
> careful of the lazy functions in clojure like map.  It will only
> execute when you ask a value for it.

render should do that

> 
> Matt Hoyt 
> 
>
> 
*From:* Dennis Haupt 
> *To:* clojure@googlegroups.com *Sent:* Saturday, September 24, 2011
> 2:36 PM *Subject:* beginner question
> 
> in java, i would start coding a game with a loop like this: while
> (true) { logic(); render(); }
> 
> i would store the current state of the world in an object
> containing the complete data of the whole game and update its
> values in each iteration.
> 
> how would i do this in clojure?
> 
> the outer loop could look like (def next [oldstate] ()) <-
> input = current game, return value = next iteration
> 
> (loop [world initalState] (recur (next world))) // <- the loop
> 
> but how would be world look like? the "best" (most trivial) thing
> that i could think of is for it to be a map which is passed along
> several transform functions, for example
> 
> (def playerHealthRegen [world] (...)) <- input = world (a map),
> output = a new map with a new entry at key "playerhealth"
> 
> each function would then return a slightly modified version of the 
> world, and at the end, i'll have my completely new state.
> 
> is that about right? or is there a completely different way i
> overlooked?
> 
> 
> -- You received this message because you are subscribed to the
> Google Groups "Clojure" group. To post to this group, send email to
> clojure@googlegroups.com <mailto:clojure@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+unsubscr...@googlegroups.com
> <mailto:unsubscr...@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 the
> Google Groups "Clojure" group. To post to this group, send email to
> clojure@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+unsubscr...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/clojure?hl=en


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOfkN+AAoJENRtux+h35aGWBkQAKnIObEE9/uJV2FdOnOLEZ0P
nDSqdKvGr95+OdX24cTQqYcnsjYogaUSFaDjTEl95x68B2SKcAxKSrl35KMbAfry
pSYmcrRDEjDzjKMQf8RY1h5IMvacJFvpcuCX+VT96RCqBwTtjaLC4xG/iGpwLD5T
n9BAn6D5Js5HosAXg5bsu+0g4Lg04L/skaRsrPtA6YvwEkA+7IMCX2Y1s6zmZwYD
ciNWhVvBFsLiFtrPSmgCRw3tAPBWjx8JrtjvMtq5nrdi3hBQMUtSxOdTwWhbKwdT
V4LwynaTt8fusXVrV9cKlWVHH28o6OED2j8fh+Ndrz6MiG89Pjp0DXIYfHJECS4a
N5Pwvs1ID2l78yhoAlmU6IvaQyEcqqR2NzTxqXrv/HqbUYbfnZeX3HX7d6sCTec9
bJ3fFn0mpW8WFF7VCE08A90bNepISBcTMJ7RsI4fRoke/Vvt0DFU3IjyfHwy/Cil
4n3Slt0UsuCIZi+p+sG6zrI4PXDJ4JZ3QoWP7VQM2IerVPAdqw4srP2MHwrwQ17J
MdZFqqEF9ANke+rqQQDiZUGizgA8UT/VYlwUOHnKGqBoegt2TUhb69htvbaKwAIJ
PZMXbKn7eImS/KUQTNFZNYaKWkJJsE4HJ9Ac2EearQ8R6I6N65BKBITdXp+jVd2s
mgt8Hyn3Lgbdk4mTVH8U
=tnGf
-END PGP SIGNATURE-

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

Re: beginner question

2011-09-24 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

i assumed my game to be so much fun that no one would ever want to
stop playing it.

Am 24.09.2011 22:26, schrieb Matt Hoyt:
> You need a check in the loop to see if the player wants to end the
> game. Clojure doesn't have a break statement like Java so you
> created a infinite loop that will never end.  To make sure the game
> ends you need to have a base case.  Example of a main game loop in
> clojure:
> 
> (loop [game-state initial-state] (if (game-ends? game-state) 
> (close-game game-state) (recur (render (logic game-state)
> 
> You should also look into records to store the game's state.
> Records are faster than hash maps and you have polymorphism with
> protocols.

if i remember correctly, deftype = map, defrecord = class?
how does "assoc" work on records?


 Be
> careful of the lazy functions in clojure like map.  It will only
> execute when you ask a value for it.

render should do that

> 
> Matt Hoyt 
> 
>
> 
*From:* Dennis Haupt 
> *To:* clojure@googlegroups.com *Sent:* Saturday, September 24, 2011
> 2:36 PM *Subject:* beginner question
> 
> in java, i would start coding a game with a loop like this: while
> (true) { logic(); render(); }
> 
> i would store the current state of the world in an object
> containing the complete data of the whole game and update its
> values in each iteration.
> 
> how would i do this in clojure?
> 
> the outer loop could look like (def next [oldstate] ()) <-
> input = current game, return value = next iteration
> 
> (loop [world initalState] (recur (next world))) // <- the loop
> 
> but how would be world look like? the "best" (most trivial) thing
> that i could think of is for it to be a map which is passed along
> several transform functions, for example
> 
> (def playerHealthRegen [world] (...)) <- input = world (a map),
> output = a new map with a new entry at key "playerhealth"
> 
> each function would then return a slightly modified version of the 
> world, and at the end, i'll have my completely new state.
> 
> is that about right? or is there a completely different way i
> overlooked?
> 
> 
> -- You received this message because you are subscribed to the
> Google Groups "Clojure" group. To post to this group, send email to
> clojure@googlegroups.com <mailto:clojure@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+unsubscr...@googlegroups.com
> <mailto:unsubscr...@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 the
> Google Groups "Clojure" group. To post to this group, send email to
> clojure@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+unsubscr...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/clojure?hl=en


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOfkN+AAoJENRtux+h35aGWBkQAKnIObEE9/uJV2FdOnOLEZ0P
nDSqdKvGr95+OdX24cTQqYcnsjYogaUSFaDjTEl95x68B2SKcAxKSrl35KMbAfry
pSYmcrRDEjDzjKMQf8RY1h5IMvacJFvpcuCX+VT96RCqBwTtjaLC4xG/iGpwLD5T
n9BAn6D5Js5HosAXg5bsu+0g4Lg04L/skaRsrPtA6YvwEkA+7IMCX2Y1s6zmZwYD
ciNWhVvBFsLiFtrPSmgCRw3tAPBWjx8JrtjvMtq5nrdi3hBQMUtSxOdTwWhbKwdT
V4LwynaTt8fusXVrV9cKlWVHH28o6OED2j8fh+Ndrz6MiG89Pjp0DXIYfHJECS4a
N5Pwvs1ID2l78yhoAlmU6IvaQyEcqqR2NzTxqXrv/HqbUYbfnZeX3HX7d6sCTec9
bJ3fFn0mpW8WFF7VCE08A90bNepISBcTMJ7RsI4fRoke/Vvt0DFU3IjyfHwy/Cil
4n3Slt0UsuCIZi+p+sG6zrI4PXDJ4JZ3QoWP7VQM2IerVPAdqw4srP2MHwrwQ17J
MdZFqqEF9ANke+rqQQDiZUGizgA8UT/VYlwUOHnKGqBoegt2TUhb69htvbaKwAIJ
PZMXbKn7eImS/KUQTNFZNYaKWkJJsE4HJ9Ac2EearQ8R6I6N65BKBITdXp+jVd2s
mgt8Hyn3Lgbdk4mTVH8U
=tnGf
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-24 Thread Matt Hoyt
You need a check in the loop to see if the player wants to end the game.  
Clojure doesn't have a break statement like Java so you created a infinite loop 
that will never end.  To make sure the game ends you need to have a base case.  
Example of a main game loop in clojure:

(loop [game-state initial-state]
  (if (game-ends? game-state)
    (close-game game-state)
    (recur (render (logic game-state)

You should also look into records to store the game's state.  Records are 
faster than hash maps and you have polymorphism with protocols.  Be careful of 
the lazy functions in clojure like map.  It will only execute when you ask a 
value for it. 
 
Matt Hoyt



From: Dennis Haupt 
To: clojure@googlegroups.com
Sent: Saturday, September 24, 2011 2:36 PM
Subject: beginner question

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

in java, i would start coding a game with a loop like this:
while (true) {
logic();
render();
}

i would store the current state of the world in an object containing
the complete data of the whole game and update its values in each
iteration.

how would i do this in clojure?

the outer loop could look like
(def next [oldstate] ()) <- input = current game, return value =
next iteration

(loop [world initalState] (recur (next world))) // <- the loop

but how would be world look like? the "best" (most trivial) thing that
i could think of is for it to be a map which is passed along several
transform functions, for example

(def playerHealthRegen [world] (...)) <- input = world (a map), output
= a new map with a new entry at key "playerhealth"

each function would then return a slightly modified version of the
world, and at the end, i'll have my completely new state.

is that about right? or is there a completely different way i overlooked?

- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOfjE+AAoJENRtux+h35aGo0MQAMipkc8e0YTPxsWsLzaVoQuz
MtXerKHHqqbuyxy+mzlc4xFfFUfs//wQGdk/ExZhby7eNVBc9AGYKarCyG/DVxfM
HwN7RVHIKDtWoHQk71dthSAzkHgbZvFxjO2W3EkI10rTsCYNFx1WV4o/PMt/KYJj
phmtO9LcHmb/ySsLveTmSdJTYjSDb7ENudLbM2z/4SP9AqN21sU1HRNF/Y4gLnq3
tnnGmbpRU8Xs6xv8O8oluRrhjgpGF58okG+JnnW+aqF95OaDMp2dQ2mPKxcWLzmt
zkMj41jC28By05oVPIIOstB50rOzU0VAQvEJRDohz2E2sxbhFfUci7G/75hvBkYz
vUXeQi4TCYM/gQlOOiAqUuutWpYWBbgL7OOHck3VkGn7UEKBguhkMTO/xGJjFxbY
6/pxIy7i7+DbSXfq+tu5sw2XAS96tctD1dWVdFjfpKukckvcDff3/L0ObKwIxTQu
BN9tqoUOs1Tp2OBJhkEJfaBMgUKqX5+IW/mKARVywNFLRWTAYs74OTO86ei/jTPo
kqwu2NGE9p/iHpLAxin8sz6I34kOlHJ2X7Xi4PBC19mmVgErt+A8MIvELuxhKBYw
BxoWZ11bccphKHFUdEDaj43pd1DqFhLqqpDvFWumUIO48pnDRpYcYcRLZ/6raCXv
apIq/CL5V7UHCJ+d/ANo
=Ckx2
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: beginner question

2011-09-24 Thread John
To break down the update into multiple steps use the -> macro:

=>(defn step [world-state])
  (-> world-state
update-health
update-physics
update-ai))

where e.g. update-health is something like

=>(defn update-health [world-state]
  (update-in world-state [:player :health] inc))

then yeah just iterate or loop/recur

=>(take 20 (iterate step init-state))

this is the purely functional way of doing it.



On Sep 24, 3:36 pm, Dennis Haupt  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> in java, i would start coding a game with a loop like this:
> while (true) {
> logic();
> render();
>
> }
>
> i would store the current state of the world in an object containing
> the complete data of the whole game and update its values in each
> iteration.
>
> how would i do this in clojure?
>
> the outer loop could look like
> (def next [oldstate] ()) <- input = current game, return value =
> next iteration
>
> (loop [world initalState] (recur (next world))) // <- the loop
>
> but how would be world look like? the "best" (most trivial) thing that
> i could think of is for it to be a map which is passed along several
> transform functions, for example
>
> (def playerHealthRegen [world] (...)) <- input = world (a map), output
> = a new map with a new entry at key "playerhealth"
>
> each function would then return a slightly modified version of the
> world, and at the end, i'll have my completely new state.
>
> is that about right? or is there a completely different way i overlooked?
>
> - --
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.14 (MingW32)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/
>
> iQIcBAEBAgAGBQJOfjE+AAoJENRtux+h35aGo0MQAMipkc8e0YTPxsWsLzaVoQuz
> MtXerKHHqqbuyxy+mzlc4xFfFUfs//wQGdk/ExZhby7eNVBc9AGYKarCyG/DVxfM
> HwN7RVHIKDtWoHQk71dthSAzkHgbZvFxjO2W3EkI10rTsCYNFx1WV4o/PMt/KYJj
> phmtO9LcHmb/ySsLveTmSdJTYjSDb7ENudLbM2z/4SP9AqN21sU1HRNF/Y4gLnq3
> tnnGmbpRU8Xs6xv8O8oluRrhjgpGF58okG+JnnW+aqF95OaDMp2dQ2mPKxcWLzmt
> zkMj41jC28By05oVPIIOstB50rOzU0VAQvEJRDohz2E2sxbhFfUci7G/75hvBkYz
> vUXeQi4TCYM/gQlOOiAqUuutWpYWBbgL7OOHck3VkGn7UEKBguhkMTO/xGJjFxbY
> 6/pxIy7i7+DbSXfq+tu5sw2XAS96tctD1dWVdFjfpKukckvcDff3/L0ObKwIxTQu
> BN9tqoUOs1Tp2OBJhkEJfaBMgUKqX5+IW/mKARVywNFLRWTAYs74OTO86ei/jTPo
> kqwu2NGE9p/iHpLAxin8sz6I34kOlHJ2X7Xi4PBC19mmVgErt+A8MIvELuxhKBYw
> BxoWZ11bccphKHFUdEDaj43pd1DqFhLqqpDvFWumUIO48pnDRpYcYcRLZ/6raCXv
> apIq/CL5V7UHCJ+d/ANo
> =Ckx2
> -END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: beginner question

2011-09-24 Thread Alan Malloy
This is about right, though instead of a loop/recur you can just (map
render (iterate next-state start-state))

On Sep 24, 12:36 pm, Dennis Haupt  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> in java, i would start coding a game with a loop like this:
> while (true) {
> logic();
> render();
>
> }
>
> i would store the current state of the world in an object containing
> the complete data of the whole game and update its values in each
> iteration.
>
> how would i do this in clojure?
>
> the outer loop could look like
> (def next [oldstate] ()) <- input = current game, return value =
> next iteration
>
> (loop [world initalState] (recur (next world))) // <- the loop
>
> but how would be world look like? the "best" (most trivial) thing that
> i could think of is for it to be a map which is passed along several
> transform functions, for example
>
> (def playerHealthRegen [world] (...)) <- input = world (a map), output
> = a new map with a new entry at key "playerhealth"
>
> each function would then return a slightly modified version of the
> world, and at the end, i'll have my completely new state.
>
> is that about right? or is there a completely different way i overlooked?
>
> - --
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.14 (MingW32)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/
>
> iQIcBAEBAgAGBQJOfjE+AAoJENRtux+h35aGo0MQAMipkc8e0YTPxsWsLzaVoQuz
> MtXerKHHqqbuyxy+mzlc4xFfFUfs//wQGdk/ExZhby7eNVBc9AGYKarCyG/DVxfM
> HwN7RVHIKDtWoHQk71dthSAzkHgbZvFxjO2W3EkI10rTsCYNFx1WV4o/PMt/KYJj
> phmtO9LcHmb/ySsLveTmSdJTYjSDb7ENudLbM2z/4SP9AqN21sU1HRNF/Y4gLnq3
> tnnGmbpRU8Xs6xv8O8oluRrhjgpGF58okG+JnnW+aqF95OaDMp2dQ2mPKxcWLzmt
> zkMj41jC28By05oVPIIOstB50rOzU0VAQvEJRDohz2E2sxbhFfUci7G/75hvBkYz
> vUXeQi4TCYM/gQlOOiAqUuutWpYWBbgL7OOHck3VkGn7UEKBguhkMTO/xGJjFxbY
> 6/pxIy7i7+DbSXfq+tu5sw2XAS96tctD1dWVdFjfpKukckvcDff3/L0ObKwIxTQu
> BN9tqoUOs1Tp2OBJhkEJfaBMgUKqX5+IW/mKARVywNFLRWTAYs74OTO86ei/jTPo
> kqwu2NGE9p/iHpLAxin8sz6I34kOlHJ2X7Xi4PBC19mmVgErt+A8MIvELuxhKBYw
> BxoWZ11bccphKHFUdEDaj43pd1DqFhLqqpDvFWumUIO48pnDRpYcYcRLZ/6raCXv
> apIq/CL5V7UHCJ+d/ANo
> =Ckx2
> -END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


beginner question

2011-09-24 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

in java, i would start coding a game with a loop like this:
while (true) {
logic();
render();
}

i would store the current state of the world in an object containing
the complete data of the whole game and update its values in each
iteration.

how would i do this in clojure?

the outer loop could look like
(def next [oldstate] ()) <- input = current game, return value =
next iteration

(loop [world initalState] (recur (next world))) // <- the loop

but how would be world look like? the "best" (most trivial) thing that
i could think of is for it to be a map which is passed along several
transform functions, for example

(def playerHealthRegen [world] (...)) <- input = world (a map), output
= a new map with a new entry at key "playerhealth"

each function would then return a slightly modified version of the
world, and at the end, i'll have my completely new state.

is that about right? or is there a completely different way i overlooked?

- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOfjE+AAoJENRtux+h35aGo0MQAMipkc8e0YTPxsWsLzaVoQuz
MtXerKHHqqbuyxy+mzlc4xFfFUfs//wQGdk/ExZhby7eNVBc9AGYKarCyG/DVxfM
HwN7RVHIKDtWoHQk71dthSAzkHgbZvFxjO2W3EkI10rTsCYNFx1WV4o/PMt/KYJj
phmtO9LcHmb/ySsLveTmSdJTYjSDb7ENudLbM2z/4SP9AqN21sU1HRNF/Y4gLnq3
tnnGmbpRU8Xs6xv8O8oluRrhjgpGF58okG+JnnW+aqF95OaDMp2dQ2mPKxcWLzmt
zkMj41jC28By05oVPIIOstB50rOzU0VAQvEJRDohz2E2sxbhFfUci7G/75hvBkYz
vUXeQi4TCYM/gQlOOiAqUuutWpYWBbgL7OOHck3VkGn7UEKBguhkMTO/xGJjFxbY
6/pxIy7i7+DbSXfq+tu5sw2XAS96tctD1dWVdFjfpKukckvcDff3/L0ObKwIxTQu
BN9tqoUOs1Tp2OBJhkEJfaBMgUKqX5+IW/mKARVywNFLRWTAYs74OTO86ei/jTPo
kqwu2NGE9p/iHpLAxin8sz6I34kOlHJ2X7Xi4PBC19mmVgErt+A8MIvELuxhKBYw
BxoWZ11bccphKHFUdEDaj43pd1DqFhLqqpDvFWumUIO48pnDRpYcYcRLZ/6raCXv
apIq/CL5V7UHCJ+d/ANo
=Ckx2
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Beginner question to a error "please"

2010-12-20 Thread Ken Wesson
On Mon, Dec 20, 2010 at 3:55 PM, Laurent PETIT  wrote:
>
>
> 2010/12/20 Ken Wesson 
>>
>> On Mon, Dec 20, 2010 at 10:27 AM, uap12 
>> wrote:
>> > Tanks very mutch for the help.
>> > /Anders
>>
>> Of course (apply str ...) will suck the whole file into ram all at
>
> slurp will suffice to suck everything into memory

True. You need a seq view of the file, perhaps with line-seq or
perhaps with a seq wrapper around the stream to get a char seq. The
latter can probably be hacked up fairly quickly using lazy-seq; it's
surprising it's not (to my knowledge) in core, really.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Beginner question to a error "please"

2010-12-20 Thread Laurent PETIT
2010/12/20 Ken Wesson 

> On Mon, Dec 20, 2010 at 10:27 AM, uap12 
> wrote:
> > Tanks very mutch for the help.
> > /Anders
>
> Of course (apply str ...) will suck the whole file into ram all at
>

slurp will suffice to suck everything into memory


> once, eagerly. If it's a multi-gigabyte file expect OOME. It would be
> nice if there was a variation on re support that worked on arbitrary
> seqs -- seqs of Characters, at least, and preferably (with suitable
> additional features) perhaps also seqs of other objects. (Ultimately,
> it always boils down to a test of whether a particular object meets
> some criterion. Sometimes that's equality with a particular other
> object; sometimes membership in a range. Using = and, with ranges,
> compare with the endpoints seems like it should generalize well, but
> you might want to be able to supply a set of class-comparator pairs.
> These could be combined into a multimethod under the hood that acts as
> a global comparator during what followed. Ranges wouldn't always make
> sense, such as for maps and sets; lists, seqs, and vectors might have
> a default comparison that generalizes that for strings, though that
> will wedge if two equal, infinite seqs ever get compared. Then again
> so will =.)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Beginner question to a error "please"

2010-12-20 Thread Ken Wesson
On Mon, Dec 20, 2010 at 10:27 AM, uap12  wrote:
> Tanks very mutch for the help.
> /Anders

Of course (apply str ...) will suck the whole file into ram all at
once, eagerly. If it's a multi-gigabyte file expect OOME. It would be
nice if there was a variation on re support that worked on arbitrary
seqs -- seqs of Characters, at least, and preferably (with suitable
additional features) perhaps also seqs of other objects. (Ultimately,
it always boils down to a test of whether a particular object meets
some criterion. Sometimes that's equality with a particular other
object; sometimes membership in a range. Using = and, with ranges,
compare with the endpoints seems like it should generalize well, but
you might want to be able to supply a set of class-comparator pairs.
These could be combined into a multimethod under the hood that acts as
a global comparator during what followed. Ranges wouldn't always make
sense, such as for maps and sets; lists, seqs, and vectors might have
a default comparison that generalizes that for strings, though that
will wedge if two equal, infinite seqs ever get compared. Then again
so will =.)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Beginner question to a error "please"

2010-12-20 Thread uap12
Tanks very mutch for the help.
/Anders

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Beginner question to a error "please"

2010-12-20 Thread Laurent PETIT
2010/12/20 uap12 

> Hi,
> I just started a hobby project, it download a webbpage, and extract number
> data witch exits between Start rad:   --and --  
> Example
> Start rad:01 20 20 52 32 85 89
>
> Everything works fine exept -main witch gives a error i don't understand.
> Becurse i try to learn Clojure, i like to now what's wrong a way :)
>
> Here is my code
> 
> (ns com.persson.extract
> ;(:import )
> ;(:require )
> )
>
> (defn remove-endlines [file]
>   (filter #(not= % \newline)
> (filter #(not= % \return) file)))
>
> (defn get-file-without-endlines[file]
> (remove-endlines (slurp file) ))
>
> (defn -main[]
> (re-find #"Start rad:<\/SPAN>*.<\/TD>" (get-file-without-endlines
> "E:/testing/data/1999_1.txt" )))
>
> And here is the error
>
> ---
> com.persson.extract=> (-main)
> # cannot be cast to java.lang.CharSequence (NO_SOURCE_FILE:117)>
>
>
The return value of get-file-without-endlines will be a seq of Chars, while
re-find expects a CharSequence (generally a String).
So to follow in the spirit of your example, you'd have to first convert your
seq of Chars back into a string, e.g. via
(apply str (get-file-without-endlines ))

HTH,

-- 
Laurent


> Best regards
> Anders
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Beginner question to a error "please"

2010-12-20 Thread uap12
Hi,
I just started a hobby project, it download a webbpage, and extract number 
data witch exits between Start rad:   --and --  
Example
Start rad:01 20 20 52 32 85 89

Everything works fine exept -main witch gives a error i don't understand.
Becurse i try to learn Clojure, i like to now what's wrong a way :)

Here is my code

(ns com.persson.extract
;(:import )
;(:require )
)

(defn remove-endlines [file]
  (filter #(not= % \newline)
(filter #(not= % \return) file)))

(defn get-file-without-endlines[file]
(remove-endlines (slurp file) ))

(defn -main[]
(re-find #"Start rad:<\/SPAN>*.<\/TD>" (get-file-without-endlines 
"E:/testing/data/1999_1.txt" )))

And here is the error
---
com.persson.extract=> (-main)
#

Best regards
Anders

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: working with agents and atoms - a beginner question

2010-06-17 Thread Ryan Waters
After reading your posts and thinking "wouldn't it be nice to just
kick off a thread and not care about the return value" I recall Rich
using/liking [1] the Java Executor framework [2].   I looked at
clojure.lang.Agent and saw it used there, too.  It's tricky because I
wouldn't want to lean on Java too much for something this fundamental
or go too far without expecting to have to code something as
complicated as what's found in core.clj (with possible java mechanics
as found in RT.java).

I picture wanting a system that can kick off workers (Executor
framework) that only needs start() and join() semantics.  I haven't
gone through all the Executor and related stuff yet so I still need to
read about everything that's available.

- - -

[1] http://clojure.org/concurrent_programming
[2] http://www.ibm.com/developerworks/java/library/j-jtp1126.html




On Wed, Jun 16, 2010 at 3:51 PM, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 16.06.2010 um 22:34 schrieb Christophe Grand:
>
>> I agree, it still feels a little dirty to use a future without caring
>> about the return value but on the positive said you get an easy way to
>> block and wait for the tread to finish (deref) and you also get
>> future-done?, future-cancel and future-cancelled which can prove
>> useful.
>
> True. This infrastructure is an incentive to use future. Maybe one can wash 
> away the dirty feeling by believing, that deref'ing is actually a 
> syncronisation point of sorts and the return value just a "side-effect".
>
> Sincerely
> Meikel
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-16 Thread Meikel Brandmeyer
Hi,

Am 16.06.2010 um 22:34 schrieb Christophe Grand:

> I agree, it still feels a little dirty to use a future without caring
> about the return value but on the positive said you get an easy way to
> block and wait for the tread to finish (deref) and you also get
> future-done?, future-cancel and future-cancelled which can prove
> useful.

True. This infrastructure is an incentive to use future. Maybe one can wash 
away the dirty feeling by believing, that deref'ing is actually a 
syncronisation point of sorts and the return value just a "side-effect".

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-16 Thread Christophe Grand
On Wed, Jun 16, 2010 at 10:20 PM, Meikel Brandmeyer  wrote:
> The typical solution for your problem would probably be:
>
> (->> long-running-function-with-recur Thread. .start)
>
> This starts you function in a dedicated thread and you can save the overhead 
> of send-off and use recur directly. I'm unsure about using future here. For 
> me future is a thing, which returns something. Using it for a process which 
> does return something useful seems "dirty" to me.

I agree, it still feels a little dirty to use a future without caring
about the return value but on the positive said you get an easy way to
block and wait for the tread to finish (deref) and you also get
future-done?, future-cancel and future-cancelled which can prove
useful.

Christophe


-- 
European Clojure Training Session: Brussels, 23-25/6 http://conj-labs.eu/
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-16 Thread Meikel Brandmeyer
Hi,

Am 15.06.2010 um 23:27 schrieb Ryan Waters:

> Thank you for pointing that out.  I notice your style is similar to
> Rich's in his ant.clj [1] which seems like the kind of solution that
> might be used in other functional and/or lisp languages.  Do you know
> if that's the case with self-calling functions and agents?  However,
> isn't there more overhead with calls to send-off instead of recur?

Yes, there is additional overhead. However hijacking a thread from agent thread 
pool (even if send-off) is misusing agents as Christophe said. Agents is about 
updating states. Not about (long running) threads.

The typical solution for your problem would probably be:

(->> long-running-function-with-recur Thread. .start)

This starts you function in a dedicated thread and you can save the overhead of 
send-off and use recur directly. I'm unsure about using future here. For me 
future is a thing, which returns something. Using it for a process which does 
return something useful seems "dirty" to me.

> I understand functions sent to an agent will only run one at a time,
> fifo-style, but was under the impression *agent* was for the current
> "main" thread of the program.  Does *agent* instead refer to whatever
> is the current thread in the function's runtime context?  Hope that
> question makes sense.

*agent* is bound to the agent whose action we are currently running in this 
thread. So concurrently running actions see different *agent*s.

Hope this helps.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-16 Thread Ryan Waters
On Wed, Jun 16, 2010 at 12:17 AM, Christophe Grand
 wrote:
> Hi Ryan,
>
> On Tue, Jun 15, 2010 at 6:01 PM, Ryan Waters  wrote:
>> I'm working with the code at the following gist and also pasted below:
>>
>> http://gist.github.com/421550
>>
>> I'd like to have execution of a separate thread (agent) continue
>> running until it sees the atom 'running' change to false.
>>
>> Unfortunately, the program doesn't return from the send-off but
>> to my understanding it should.  Why won't it return?  I'm using
>> clojure 1.1.
>
> It does return from send-off -- in your gist's version at last thanks
> to Shawn but there are still other errors.
>
>> (ns nmanage)
>>
>> (def running (atom true))
>>
>> (defn process
>>  []
>
> A fn sent as an action to an agent must accept at least one arg: the
> agent's current value (if additional args are passed to args, the
> action fn must accept them too). So the above line should be [_] (_ to
> signify that you don't care about the value) instead of []
>

Thank you - I was unaware that a function sent to an agent had to
accept at least one arg.

>>  (when @running
>>    (prn "hi")
>>    (Thread/sleep 1000))
>>  (recur))
>
> Here your recur is misplaced, you want to recur when @running is true
> so the (recur) should be at the end of the when form and it should
> have an extra argument since we changed process to take one arg.
> However this when/recur pattern is what the while macro expands to.
>
> (defn process [_]
>  (while @running
>   (prn "hi")
>   (Thread/sleep 1000)))
>

Very true - in this example, I totally agree.  The example I put
together is a simplified version of the program I'm working on which
uses some file I/O.  I'm wanting to tail a file and process its
contents over time so I had a loop that would read the file until it
started reading 'nil', then sleep, then try again, creating a loop
within a loop (and polling the file for new contents).  In trying to
keep the example program faithful to the other, I ended up with some
nonsensical clojure  ; )

>
>> ;;;
>> (send-off (agent nil) (process))
>
> Here it should be (send-off (agent nil) process) but Shawn already
> pointed this out.
>
> I think that using an agent and not caring about its value is kind of
> an abuse, better use a future.
>
> (def running (atom true))
>
> (future
>  (while @running
>    (prn "hi")
>    (Thread/sleep 1000)))
>

Here my near total ignorance of futures comes into play.  Thank you
very much for pointing this out as a better way.  I've been so eager
to write a first program in clojure that I haven't gotten through all
the 1.1 (and 1.0) language features yet. :D


> ;;;
> (do
>  (prn "this prints now - fixed thanks to Shawn Hoover")
>  (Thread/sleep 2000)
>  (reset! running false))
>
> hth,
>
> Christophe
>
> --
> European Clojure Training Session: Brussels, 23-25/6 http://conj-labs.eu/
> Professional: http://cgrand.net/ (fr)
> On Clojure: http://clj-me.cgrand.net/ (en)
>

I appreciate yours and everyone's valuable time!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-16 Thread Ryan Waters
Thank you for pointing that out.  I notice your style is similar to
Rich's in his ant.clj [1] which seems like the kind of solution that
might be used in other functional and/or lisp languages.  Do you know
if that's the case with self-calling functions and agents?  However,
isn't there more overhead with calls to send-off instead of recur?

I understand functions sent to an agent will only run one at a time,
fifo-style, but was under the impression *agent* was for the current
"main" thread of the program.  Does *agent* instead refer to whatever
is the current thread in the function's runtime context?  Hope that
question makes sense.


[1]
http://clojure.googlegroups.com/web/ants.clj?gda=uyYClToAAADrLV-d6p24hYFcam_S99IgeBuuRL78NgAsI-ljfFHCWu9OU0NQiFWgQuhmPR7veGf97daDQaep90o7AOpSKHW0


On Tue, Jun 15, 2010 at 3:03 PM, Meikel Brandmeyer  wrote:
> Hi,
>
> besides the answer you got from Shawn, I'd like to question your use of the 
> agent system. This is not the way it is supposed to be used. To model a 
> processing loop with agents you should send the action back to the agent 
> itself.
>
> (def running? (atom true))
>
> (defn process
>  [agent-state step]
>  (when @running?
>    (send-off *agent* process (inc step)))
>  (+ agent-state step))
>
> (def a (agent 0))
> (send-off a process 1)
> (Thread/sleep 100)
> (reset! running? false)
>
> Note: in an action *agent* refers to the current agent.
>
> Sincerely
> Meikel
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-16 Thread Ryan Waters
On Tue, Jun 15, 2010 at 12:23 PM, Shawn Hoover  wrote:
>
> On Tue, Jun 15, 2010 at 12:01 PM, Ryan Waters  wrote:
>>
>> I'm working with the code at the following gist and also pasted below:
>>
>> http://gist.github.com/421550
>>
>> I'd like to have execution of a separate thread (agent) continue
>> running until it sees the atom 'running' change to false.
>>
>> Unfortunately, the program doesn't return from the send-off but
>> to my understanding it should.  Why won't it return?  I'm using
>> clojure 1.1.
>>
>> TIA
>>
>> 
>>
>> (ns nmanage)
>>
>> (def running (atom true))
>>
>> (defn process
>>  []
>>  (when @running
>>    (prn "hi")
>>    (Thread/sleep 1000))
>>  (recur))
>>
>> ;;;
>> (send-off (agent nil) (process))
>>
>> (do
>>  (prn "this won't print - execution doesn't make it this far")
>>  (Thread/sleep 2000)
>>  (reset! running false))
>>
>
> It looks like you're passing the result of calling (process) as an argument
> to send-off. Try just (send-off (agent nil) process) to pass the process fn
> as a value.
>

Doh!  I should have caught that  : )

Thank you for your help!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-15 Thread Christophe Grand
Hi Ryan,

On Tue, Jun 15, 2010 at 6:01 PM, Ryan Waters  wrote:
> I'm working with the code at the following gist and also pasted below:
>
> http://gist.github.com/421550
>
> I'd like to have execution of a separate thread (agent) continue
> running until it sees the atom 'running' change to false.
>
> Unfortunately, the program doesn't return from the send-off but
> to my understanding it should.  Why won't it return?  I'm using
> clojure 1.1.

It does return from send-off -- in your gist's version at last thanks
to Shawn but there are still other errors.

> (ns nmanage)
>
> (def running (atom true))
>
> (defn process
>  []

A fn sent as an action to an agent must accept at least one arg: the
agent's current value (if additional args are passed to args, the
action fn must accept them too). So the above line should be [_] (_ to
signify that you don't care about the value) instead of []

>  (when @running
>    (prn "hi")
>    (Thread/sleep 1000))
>  (recur))

Here your recur is misplaced, you want to recur when @running is true
so the (recur) should be at the end of the when form and it should
have an extra argument since we changed process to take one arg.
However this when/recur pattern is what the while macro expands to.

(defn process [_]
 (while @running
   (prn "hi")
   (Thread/sleep 1000)))


> ;;;
> (send-off (agent nil) (process))

Here it should be (send-off (agent nil) process) but Shawn already
pointed this out.

I think that using an agent and not caring about its value is kind of
an abuse, better use a future.

(def running (atom true))

(future
  (while @running
(prn "hi")
(Thread/sleep 1000)))

;;;
(do
  (prn "this prints now - fixed thanks to Shawn Hoover")
  (Thread/sleep 2000)
  (reset! running false))

hth,

Christophe

-- 
European Clojure Training Session: Brussels, 23-25/6 http://conj-labs.eu/
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-15 Thread Meikel Brandmeyer
Hi,

besides the answer you got from Shawn, I'd like to question your use of the 
agent system. This is not the way it is supposed to be used. To model a 
processing loop with agents you should send the action back to the agent itself.

(def running? (atom true))

(defn process
  [agent-state step]
  (when @running?
(send-off *agent* process (inc step)))
  (+ agent-state step))

(def a (agent 0))
(send-off a process 1)
(Thread/sleep 100)
(reset! running? false)

Note: in an action *agent* refers to the current agent.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: working with agents and atoms - a beginner question

2010-06-15 Thread Shawn Hoover
On Tue, Jun 15, 2010 at 12:01 PM, Ryan Waters  wrote:

> I'm working with the code at the following gist and also pasted below:
>
> http://gist.github.com/421550
>
> I'd like to have execution of a separate thread (agent) continue
> running until it sees the atom 'running' change to false.
>
> Unfortunately, the program doesn't return from the send-off but
> to my understanding it should.  Why won't it return?  I'm using
> clojure 1.1.
>
> TIA
>
> 
>
> (ns nmanage)
>
> (def running (atom true))
>
> (defn process
>  []
>  (when @running
>(prn "hi")
>(Thread/sleep 1000))
>  (recur))
>
> ;;;
> (send-off (agent nil) (process))
>
> (do
>  (prn "this won't print - execution doesn't make it this far")
>  (Thread/sleep 2000)
>  (reset! running false))
>
>
It looks like you're passing the result of calling (process) as an argument
to send-off. Try just (send-off (agent nil) process) to pass the process fn
as a value.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

working with agents and atoms - a beginner question

2010-06-15 Thread Ryan Waters
I'm working with the code at the following gist and also pasted below:

http://gist.github.com/421550

I'd like to have execution of a separate thread (agent) continue
running until it sees the atom 'running' change to false.

Unfortunately, the program doesn't return from the send-off but
to my understanding it should.  Why won't it return?  I'm using
clojure 1.1.

TIA



(ns nmanage)

(def running (atom true))

(defn process
  []
  (when @running
(prn "hi")
(Thread/sleep 1000))
  (recur))

;;;
(send-off (agent nil) (process))

(do
  (prn "this won't print - execution doesn't make it this far")
  (Thread/sleep 2000)
  (reset! running false))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en