<div class="gmail_quote">On Fri, Feb 3, 2012 at 1:40 AM, Raymond Toy <span dir="ltr"><<a href="mailto:toy.raymond@gmail.com">toy.raymond@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
1. You have to check after reading the string to see what it contains. (I guess a very small compile-time cost.)<br></blockquote><div><br></div><div>Indeed the cost is very small and can be included in the routine that reads the string into the buffer.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2. Because I didn't think any lisp did that, but it's not illegal to do so.<br>
3. It's a burden on the user if the type of a constant string depends on what's in it. Being illiterate, I only know ASCII, so, perhaps this isn't a problem in practice.<br></blockquote></div><br>I implemented this because after I introduced Unicode all programs began using 4 times more memory than non-unicode versions of it. It is natural: symbols, strings, code, all data can be either base-string or extended-strings and if the core does not try to save space, everything defaults to the most expensive version.<div>
<br></div><div>In practice this should never be a problem.</div><div><br></div><div>* Constants do not need declarations in any of the lisps I know. I mean, in your fortran2cl code, (LET ((A "fooo")) ...) when the variable A is not modified, immediately tells the compiler that it can replace the variable with a constant.</div>
<div><br></div><div>* Constants are not meant to be overwritten, never. This is very clear in the spec. From that point of view, the user should not care whether the constant is a simple array or not, or whether it contains one type of elements or another. If you need modifiable arrays in the fortran code, then those LET statements should not contain assignments of constants, but rather a (copy-seq 'string "whateverconstantyouused").</div>
<div><br></div><div>* The user should not expect one or another type of array from a constant that is read in an non-readable form. More precisely, "aaaa" does not specify anything about the array type. The array forms #A do. I understand this is a problem with the ANSI specification, which states explicitly that *print-readably* cannot affect how strings and symbols are printed :-/ That is unfortunate and probable arises from a balance between readability and utility of the printed output.</div>
<div><br></div><div>I had a look at f2cl's code and the following code would more or less fix it. There might be simpler ways, such as looking only at PARAMETER statements, but my fortran is a bit rusty and I do not know f2cl so well. Note also that one possible optimization could be to use LOAD-TIME-VALUE around COERCE, for those lisps that would not precompute the COERCE statement.</div>
<div><br></div><div><div>diff --git a/src/f2cl1.l b/src/f2cl1.l</div><div>index 87b7ceb..907750d 100644</div><div>--- a/src/f2cl1.l</div><div>+++ b/src/f2cl1.l</div><div>@@ -1075,7 +1075,20 @@ correctly"</div><div> (if *common-block-file*</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>(do-file)</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>(do-output outport))))</div><div>- </div><div>+</div><div>+(defun fixup-unicode-strings (s)</div>
<div>+ (labels ((fixup-inner (item)</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span> (cond ((stringp item)</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span> (if (typep item '(array character (*)))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>item</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>`(coerce ,item '(array character (*)))))</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span> ((atom item)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> item)</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span> ((consp item)</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span> (mapcar #'fixup-inner item)))))</div>
<div>+ (if (subtypep 'character 'base-char)</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>s</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>(fixup-inner s))))</div>
<div> </div><div> (defun translate-and-write-subprog (prog-list outport output-path</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> declaim package options)</div><div>@@ -1151,7 +1164,7 @@ correctly"</div>
<div> ;; functions, in case the Fortran code has declared them as</div><div> ;; external.</div><div> (setf fun (fixup-f2cl-lib fun (cons (cadr fort-fun) *external-function-names*)))</div><div>- </div>
<div>+ (setf fun (fixup-unicode-strings fun))</div><div> (special-print fun outport)</div><div> (format outport "~2&(in-package #-gcl #:cl-user #+gcl \"CL-USER\")~%#+#.(cl:if (cl:find-package '#:f2cl) '(and) '(or))~%")</div>
<div> (let* ((*package* (find-package '#:cl-user))</div></div><div><br></div><div><div><br></div>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://juanjose.garciaripoll.googlepages.com" target="_blank">http://juanjose.garciaripoll.googlepages.com</a><br>
</div>