Re: hooks on namespace required/loaded

2014-02-18 Thread t x
As a point of clarification, read-string is not a hard requirement.
Just getting the name of the namespace (and walking through the
symbols + calling source on each of them to get the source code is
perfeclty fine).

Basically, I want to hook a function that
  * gets called every time a namespace is loaded/required/reloaded
  * gets passed the namespace

Thanks!

On Tue, Feb 18, 2014 at 8:32 PM, t x txrev...@gmail.com wrote:
 Hi,

   Although solutions not involving cljx are perfectly fine, I'm using
 cljx -- so solutions that involves hooking into cljx are perfectly
 fine too.

   I have my own poor-man's lint / type checker (with different
 objectives from core.typed). I want a certain function (call it
 CHECKER) to be called every time a namespace has been required /
 loaded / reloaded

   Every time I require/load/reload a namespace, I want the following to 
 happen:

 (CHECKER ... source code of the namesapce)

 i.e. something like

 (CHECKER (read-string namesapce-just-loaded.clj))

 Then, if CHECKER throws an exception, it should be a compile error. If
 CHECKER prints stuff out, it should go into the lein repl stdout,
 and if CHECKER doesn't do anything, it's assumed that the namespace
 passed the check.

   Is there a minimal example somewhere of how this works? (i.e.
 something as stupid as: this example calls a function, which just
 prints out the name of all functions defined would be extremely
 helpful).

 Thanks!

-- 
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: hooks on namespace required/loaded

2014-02-18 Thread t x
With apologies for spamming:

  Solutions that involves installing a new lein plugin is fine too.

  I'm willing to completely re-organize my workflow in order to

  * have some other piece of Clojure code gets called / do
verification whenever a clojure namespace is required/loaded/reloaded

/ Done spamming.

On Tue, Feb 18, 2014 at 8:38 PM, t x txrev...@gmail.com wrote:
 As a point of clarification, read-string is not a hard requirement.
 Just getting the name of the namespace (and walking through the
 symbols + calling source on each of them to get the source code is
 perfeclty fine).

 Basically, I want to hook a function that
   * gets called every time a namespace is loaded/required/reloaded
   * gets passed the namespace

 Thanks!

 On Tue, Feb 18, 2014 at 8:32 PM, t x txrev...@gmail.com wrote:
 Hi,

   Although solutions not involving cljx are perfectly fine, I'm using
 cljx -- so solutions that involves hooking into cljx are perfectly
 fine too.

   I have my own poor-man's lint / type checker (with different
 objectives from core.typed). I want a certain function (call it
 CHECKER) to be called every time a namespace has been required /
 loaded / reloaded

   Every time I require/load/reload a namespace, I want the following to 
 happen:

 (CHECKER ... source code of the namesapce)

 i.e. something like

 (CHECKER (read-string namesapce-just-loaded.clj))

 Then, if CHECKER throws an exception, it should be a compile error. If
 CHECKER prints stuff out, it should go into the lein repl stdout,
 and if CHECKER doesn't do anything, it's assumed that the namespace
 passed the check.

   Is there a minimal example somewhere of how this works? (i.e.
 something as stupid as: this example calls a function, which just
 prints out the name of all functions defined would be extremely
 helpful).

 Thanks!

-- 
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: hooks on namespace required/loaded

2014-02-18 Thread Joel Holdbrooks
I know we talked a bit about this in IRC but this is a hack you could use 
to slurp the file's contents into a string in that file:

(ns foo.core
  (:refer-clojure :exclude [slurp]))
 
(defmacro slurp [file]
  (clojure.core/slurp file))
 
;; In CLJS
 
(ns bar.core
  (:require [foo.core :include-macros true :refer [slurp]]))
 
;; This is possible because we can evaluate *Clojure* code at compile time.
(def project-clj 
  (slurp project.clj))


From there you could then use read-string, or what have you, and examine 
the contents.

Here's a link to the gist for 
reference: https://gist.github.com/noprompt/9086232.

On Tuesday, February 18, 2014 8:32:05 PM UTC-8, t x wrote:

 Hi, 

   Although solutions not involving cljx are perfectly fine, I'm using 
 cljx -- so solutions that involves hooking into cljx are perfectly 
 fine too. 

   I have my own poor-man's lint / type checker (with different 
 objectives from core.typed). I want a certain function (call it 
 CHECKER) to be called every time a namespace has been required / 
 loaded / reloaded 

   Every time I require/load/reload a namespace, I want the following to 
 happen: 

 (CHECKER ... source code of the namesapce) 

 i.e. something like 

 (CHECKER (read-string namesapce-just-loaded.clj)) 

 Then, if CHECKER throws an exception, it should be a compile error. If 
 CHECKER prints stuff out, it should go into the lein repl stdout, 
 and if CHECKER doesn't do anything, it's assumed that the namespace 
 passed the check. 

   Is there a minimal example somewhere of how this works? (i.e. 
 something as stupid as: this example calls a function, which just 
 prints out the name of all functions defined would be extremely 
 helpful). 

 Thanks! 


-- 
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: hooks on namespace required/loaded

2014-02-18 Thread Andy Fingerhut
I am not sure about ClojureScript, but in Clojure/Java you can use
alter-var-root to change the definition of load-libs, which is called by
both require and use.  You can use alter-var-root to change the definition
of any function you want in clojure.core or any other namespace.  I
wouldn't recommend going crazy with it, but it should be able to do the
job, at least after the alter-var-root takes effect.

Out of curiosity, what kind of linting does your function do?

Andy


On Tue, Feb 18, 2014 at 8:41 PM, t x txrev...@gmail.com wrote:

 With apologies for spamming:

   Solutions that involves installing a new lein plugin is fine too.

   I'm willing to completely re-organize my workflow in order to

   * have some other piece of Clojure code gets called / do
 verification whenever a clojure namespace is required/loaded/reloaded

 / Done spamming.

 On Tue, Feb 18, 2014 at 8:38 PM, t x txrev...@gmail.com wrote:
  As a point of clarification, read-string is not a hard requirement.
  Just getting the name of the namespace (and walking through the
  symbols + calling source on each of them to get the source code is
  perfeclty fine).
 
  Basically, I want to hook a function that
* gets called every time a namespace is loaded/required/reloaded
* gets passed the namespace
 
  Thanks!
 
  On Tue, Feb 18, 2014 at 8:32 PM, t x txrev...@gmail.com wrote:
  Hi,
 
Although solutions not involving cljx are perfectly fine, I'm using
  cljx -- so solutions that involves hooking into cljx are perfectly
  fine too.
 
I have my own poor-man's lint / type checker (with different
  objectives from core.typed). I want a certain function (call it
  CHECKER) to be called every time a namespace has been required /
  loaded / reloaded
 
Every time I require/load/reload a namespace, I want the following to
 happen:
 
  (CHECKER ... source code of the namesapce)
 
  i.e. something like
 
  (CHECKER (read-string namesapce-just-loaded.clj))
 
  Then, if CHECKER throws an exception, it should be a compile error. If
  CHECKER prints stuff out, it should go into the lein repl stdout,
  and if CHECKER doesn't do anything, it's assumed that the namespace
  passed the check.
 
Is there a minimal example somewhere of how this works? (i.e.
  something as stupid as: this example calls a function, which just
  prints out the name of all functions defined would be extremely
  helpful).
 
  Thanks!

 --
 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.


-- 
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: hooks on namespace required/loaded

2014-02-18 Thread t x
@Joel:

  While on IRC, I completely misunderstood you.

  Now, after looking at it again, it makes sense. This is very cool --
because making it a macro forces it to be evaluated at compile time,
when the source is available. Very nice. :-)

@Andy

  Thanks! I will look into load-libs.

  The following is a bit vague-ish not on purpose, but because part of
it works, part of it is still being hacked together.


## stuff I have:

This is how my current pattern matching / object system looks like:
https://gist.github.com/txrev319/9086538

In a very hackish and theoretically unsound way, each hash-map is an
object and the :tag field represents the type of the object.


## stuff that are vague because I'm still hacking them together /
thinking about them

### missing feature 1

now, I want to be able to say things like:

:animal = [:cat :dog :mouse]

then, if I do:

(hmatch obj :animal
   :dog ...
   :cat ... )

I want it to give me an error of: hey, you're not matching against
:mouse -- and I want this to happen at COMPILE time, not at run time


### missing feature 2

using standard Hindley-Milner, and using the :tag field as the type,
I want to be able to tag a function as having a certain type, and have
it verified at compile time -- this is purely optional type checking

a common pattern I run into is:

(async/go
  (loop [msg (! some-chan)]
(hmatch ...
  [:dog ... ] (call-other-function msg)
...)))

now, when I pull the msg off the channel, I have no idea what type it
is -- and that is fine.

However, I'd prefer to verify, at compile time, that
call-other-function has type :dog - :something


### in summary,

  I'm basically hacking together poor-man's pattern matching (done)
and type checking (still need more hacking). The idea is:

  * I want a dynamically typed langauge

  * I want to be able to say: for this subset of functions, they have
type signatures, and we can catch errors statically (-- and these
choices are completely adhoc, based on what errors I waste time
catching)



On Tue, Feb 18, 2014 at 9:15 PM, Andy Fingerhut
andy.finger...@gmail.com wrote:
 I am not sure about ClojureScript, but in Clojure/Java you can use
 alter-var-root to change the definition of load-libs, which is called by
 both require and use.  You can use alter-var-root to change the definition
 of any function you want in clojure.core or any other namespace.  I wouldn't
 recommend going crazy with it, but it should be able to do the job, at least
 after the alter-var-root takes effect.

 Out of curiosity, what kind of linting does your function do?

 Andy


 On Tue, Feb 18, 2014 at 8:41 PM, t x txrev...@gmail.com wrote:

 With apologies for spamming:

   Solutions that involves installing a new lein plugin is fine too.

   I'm willing to completely re-organize my workflow in order to

   * have some other piece of Clojure code gets called / do
 verification whenever a clojure namespace is required/loaded/reloaded

 / Done spamming.

 On Tue, Feb 18, 2014 at 8:38 PM, t x txrev...@gmail.com wrote:
  As a point of clarification, read-string is not a hard requirement.
  Just getting the name of the namespace (and walking through the
  symbols + calling source on each of them to get the source code is
  perfeclty fine).
 
  Basically, I want to hook a function that
* gets called every time a namespace is loaded/required/reloaded
* gets passed the namespace
 
  Thanks!
 
  On Tue, Feb 18, 2014 at 8:32 PM, t x txrev...@gmail.com wrote:
  Hi,
 
Although solutions not involving cljx are perfectly fine, I'm using
  cljx -- so solutions that involves hooking into cljx are perfectly
  fine too.
 
I have my own poor-man's lint / type checker (with different
  objectives from core.typed). I want a certain function (call it
  CHECKER) to be called every time a namespace has been required /
  loaded / reloaded
 
Every time I require/load/reload a namespace, I want the following to
  happen:
 
  (CHECKER ... source code of the namesapce)
 
  i.e. something like
 
  (CHECKER (read-string namesapce-just-loaded.clj))
 
  Then, if CHECKER throws an exception, it should be a compile error. If
  CHECKER prints stuff out, it should go into the lein repl stdout,
  and if CHECKER doesn't do anything, it's assumed that the namespace
  passed the check.
 
Is there a minimal example somewhere of how this works? (i.e.
  something as stupid as: this example calls a function, which just
  prints out the name of all functions defined would be extremely
  helpful).
 
  Thanks!

 --
 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