|
From: | kahl |
Subject: | Re: Writing verbatim to a file |
Date: | 24 Sep 2001 07:15:22 -0000 |
> > is it possible to write text/data directly into a file, > maybe with directing a copy of it as a raw-text to > the lout-document? > > This could be used to write C-Code into a file from > within a Lout-document and at the same time setting > it in the document. > > This is intended to use lout for literate programming, > where the documentation to the C-Code and the C-Code itself > will be written at the same time and will be located at the > same place, so that it is easier to maintain documentation > and code in parallel. For literate programming, I am spoiled by the capabilities of FunnelWeb (http://www.ross.net/funnelweb/). Since FunelWeb is designed to be formatter-independent, it should be possible to include a switch for lout, like there is one for TeX. (The fact that both share the @ as special could complicate the task, or make the result less attractive.) However, I have been too lazy (and C-phobic) to attempt this; instead I achieve the effect indirectly: A Lout @Filter command serves the FunnelWeb fragments to ``loutfw'', which returns one version for Lout to typeset, and appends another version to the file ``loutfw.fw''. This file has to be emptied before every Lout run; my Makefile has: fw: rm -f lout.fw lout1 $(LOUTSRC) && xfw lout.fw A fragment of $(LOUTSRC) (with Haskell code) is here: --------------------------------------------------------------- @LP #{{{ head @FunnelWeb @Begin @$@<hypergraph@>address@hidden@- > hgVarsOk :: @<HG@>@(, HyperGraph g@) -> Bool > hgVarsOk g = all (null . hgOutEdges g . snd . snd) (toListFM $ hgVars g) > hgAllVars :: @<HG@>@(, HyperGraph g@) -> Bool > hgAllVars g = all (`elem` (map (snd . snd) $ toListFM $ hgVars g)) > (filter (null . hgOutEdges g) (hgNodes g)) @} @End @FunnelWeb #}}} @LP For the calculation of depth-first search forests it is important to keep in mind that our hyper-edges are oriented bottom-up, with data flowing from the edge's sources to its targets, while edges in conventional term graphs are oriented top-down. @LP #{{{ hgDFS @FunnelWeb @Begin @$@<hypergraph@>address@hidden@- > hgDFS :: @<HG@>@(, HyperGraph g@) -> > Forest (Either n e) > hgDFS g = > let f (Left n) = map (Right . fst3) (hgInEdges g n) > f (Right e) = foldFM (\ i (s,n) l -> Left n : l) [] (hgEdgeSources g e) > in DFS.dfs f $ > foldrFM' (hgRoots g) (\ k (t,n) l -> Left n : l) > (map Left (hgNodes g) ++ map Right (hgEdges g)) @} @End @FunnelWeb #}}} @LP --------------------------------------------------------------- All FunnelWeb definitions shoud follow the pattern first line --- contents --- last line as follows: address@hidden@- contents @} Otherwise, there will be problems. The strange Lout comments are folding marks for Emacs folding mode: #{{{ EMACS lv # Local Variables: # folded-file: t # mode: iso-accents # fold-internal-margins: 0 # eval: (fold-set-marks "#{{{ " "#}}}") # eval: (fold-whole-buffer) # end: #}}} The missing bits are attached: * xfw: a shell script for easier calling of FunnelWeb * lout1: a shell script for easier calling of Lout * funnel: containing the Lout definition of @FunnelWeb * loutfw.ml: the OCaml (-labels) program producing the two versions of the code. There are a few options that influence inclusion or hiding of FunnelWeb headers and trailers and other things --- I haven't looked at it for quite some time. In addition there are two utilities, written in Haskell in the last few days, which can be handy in connection with FunnelWeb: * QuietFw.lhs: to be inserted in a pipe after xfw or fw --- it cuts out FunnelWeb messages about non-updated files. * ToFw.lhs: Takes a list of files as arguments, and produces on stdout a FunnelWeb file producing those files, with tabs expanded and trailing spaces eliminated, but without replacements of other special and 8-bit characters. Please feel free to ask if any questions remain! Wolfram
xfw
Description: Binary data
lout1
Description: Binary data
funnel
Description: Binary data
loutfw.ml
Description: Binary data
QuietFw.lhs
Description: Binary data
ToFw.lhs
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |