Then integrate the whole lot into the Clojure compiler pipeline so that
it just works in the first place.

Reid McKenzie <rmckenzi...@gmail.com> writes:

> Clearly the solution is to use tools.analyzer and write a big def emitter
>
> /s
> Reid
> On 06/04/2014 10:27 AM, Mars0i wrote:
>>
>>
>> On Wednesday, June 4, 2014 9:42:41 AM UTC-5, Mars0i wrote:
>>
>>     ... Then I add the new functions to the declarestatement by hand,
>>     or I periodically do something like:
>>
>>     grep defn mysourcefile.clj >> mysourcefile.clj
>>     (Be careful to use two ">"s!)
>>
>>     and then I edit the junk at the end of the file into a
>>     declarestatement at the top of the file.  And maybe if f I were
>>     ... lazier, I'd code a script that would update the declarein one
>>     pass.
>>
>>
>> OK, I couldn't resist my own implicit challenge.
>>
>> #!/bin/sh
>> sourcefile="$1"
>> newsourcefile="new.$sourcefile"
>>
>> newdeclare=$(echo '(declare' \
>>     `sed -n '/defn/s/(defn-* //p' "$sourcefile" | tr '\n' ' '` ')' \
>>     | sed 's/ )/)/')
>>
>> sed "s/(declare .*/$newdeclare/" "$sourcefile" > "$newsourcefile"
>>
>> This writes a new version of the file named new.<oldfilename>. Or if
>> you either trust your script or trust your backups, and are on a
>> system that includes the mighty ed
>> <http://www.gnu.org/fun/jokes/ed.msg.html> editor, you can replace the
>> last line with:
>>
>> echo "1,\$s/(declare .*/$newdeclare/\nw\n" | ed "$sourcefile"
>>
>> which edits the file in place, assuming that the previous version of
>> the declaration was on one line.  You may want to use a different
>> scriptable editor.
>>
>> The messy part is the sed and tr line:
>>
>>     `sed -n '/defn/s/(defn-* //p' "$sourcefile" | tr '\n' ' '`
>>
>> The sed part finds all of the lines with "defn" in them, then
>> substitutes the empty string for "(defn" or "(defn-".   'tr' then
>> removes the newlines between the function names, replacing the
>> newlines with spaces.  You'll need something a little more complicated
>> if you put the parameter vector or anything else on the same line as
>> the function name.  The 'echo' on the previous line, along with the
>> final ')' adds "(declare" and its closing parenthesis.  Those two
>> lines can be used by themselves to generate a declare statement from
>> the command line. The 'sed' command after these lines isn't necessary;
>> it just removes an unnecessary space before the closing parenthesis.
>>
>> Obviously, there will be source files on which this won't work.  It's
>> not worth making it foolproof.
>>
>> It's a certainty that others would code this more elegantly or more
>> succinctly.  It could be written in Clojure, obviously, but still
>> wouldn't be foolproof unless someone hacks it from the Clojure parser.
>> -- 
>> 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
>> <mailto:clojure+unsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout.

-- 
Phillip Lord,                           Phone: +44 (0) 191 222 7827
Lecturer in Bioinformatics,             Email: phillip.l...@newcastle.ac.uk
School of Computing Science,            
http://homepages.cs.ncl.ac.uk/phillip.lord
Room 914 Claremont Tower,               skype: russet_apples
Newcastle University,                   twitter: phillord
NE1 7RU                                 

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

Reply via email to