<< Back to previous view

[CLJ-1134] star-directive in clojure.pprint/cl-format with an at-prefix ("~n@*") do not obey its specifications Created: 18/Dec/12  Updated: 26/Dec/12

Status: Open
Project: Clojure
Component/s: None
Affects Version/s: Release 1.4, Release 1.5
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Jean Niklas L'orange Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: bug, pprint

Attachments: Text File clj-1134-star-directive-in-cl-format.txt    
Patch: Code and Test

 Description   

The star-directive in clojure.pprint/cl-format with an at-prefix (~n@*) does not obey its specifications according to Common Lisp the Language, 2nd Edition. There are two bugs within ~n@* as of right now:

  1. When ~n@* is supposed to jump forward over more than one argument, it jumps one step backward as if it had seen ~:*. For instance, (cl-format nil "~D ~3@*~D" 0 1 2 3) will return "0 0" and not "0 3" as expected.
  2. When ~@* is seen, the formatter is supposed to jump to the first argument (as n defaults to 0, see specification linked above). However, whenever a ~@*-directive is seen, the formatter jumps to the second argument instead.

What (small set of) steps will reproduce the problem?

Inside a clean Clojure repl, perform these steps:

user=> (require '[clojure.pprint :refer [cl-format]])
nil
user=> (cl-format nil "~D ~3@*~D" 0 1 2 3)
"0 0"                                           ;; Expected: "0 3"
user=> (cl-format nil "~D~D~D~D ~@*~D" 0 1 2 3)
"0123 1"                                        ;; Expected: "0123 0"

What is the expected output? What do you see instead?

The expected output is "0 3" and "0123 0", but is "0 0" and "0123 1" as shown above.

What version are you using?

Tested on both 1.4.0 and 1.5.0-beta2, both have the defect described.

Please provide any additional information below.

The format strings which reproduces the problem has been compared with the format function from the Common Lisp implementations SBCL, CLisp and Clozure. All of them print the expected output.



 Comments   
Comment by Jean Niklas L'orange [ 18/Dec/12 9:28 PM ]

Patch attached.

It may be easier to read the changes the patch does from within JIRA instead from the commit message, so I've added it here:

This solves two issues as specified by #CLJ-1134. Issue #1 is solved by doing a
relative jump forward within absolute-reposition in cl_format.clj, line 114 by
switching (- (:pos navigator) position) with (- position (:pos navigator)).

Issue #2 is handled by changing the default n-parameter to * depending on
whether the @-prefix is placed or not. If it is placed, then n defaults to
0, otherwise it defaults to 1.

In addition, new tests have been appended to test_cl_format.clj to ensure the
correctness of this patch. The tests have been tested on the Common Lisp
implementation GNU CLISP 2.49, which presumably handle the ~n@*
correctly. This patch and GNU CLISP returns the same output for each format
call, sans case for printed symbols; Common Lisp has case-insensitive symbols,
whereas Clojure has not.





[CLJ-1123] UNIX/Windows line endings - clojure.pprint tests cause failure in Windows build Created: 09/Dec/12  Updated: 10/Dec/12  Resolved: 10/Dec/12

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.5
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Mike Anderson Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: platform-specific, pprint
Environment:

Windows 7, Maven 3.0.4



 Description   

I ran a test build of the latest Clojure 1.5 master (372f03e) on Windows and found a number of failures in the "clojure.test-clojure.pprint" tests. All of these seem to be caused by incorrect assumptions about line endings. Example:

[java] {:clojure.test/vars (ns-macro-test),
[java] :thread/name "main",
[java] :pid 1528,
[java] :thread 1,
[java] :type :assert/fail,
[java] :level :warn,
[java] :test/actual
[java] (not
[java] (clojure.core/=
[java] "(ns slam.hound.stitch\r\n (:use [slam.hound.prettify :only [prettify]]))\r\n"
[java] "(ns slam.hound.stitch\n (:use [slam.hound.prettify :only [prettify]]))\n")),
[java] :test/expected
[java] (clojure.core/=
[java] (clojure.core/with-out-str
[java] (clojure.pprint/with-pprint-dispatch
[java] clojure.pprint/code-dispatch
[java] (clojure.pprint/pprint
[java] (clojure.core/read-string
[java] "(ns slam.hound.stitch\n (:use [slam.hound.prettify :only [prettify]]))"))))
[java] (clojure.core/str
[java] "(ns slam.hound.stitch\n (:use [slam.hound.prettify :only [prettify]]))"
[java] "\n")),
[java] :line 173,
[java] :tstamp 1355113319212,
[java] :file "test_pretty.clj"}

It isn't totally clear what the right behaviour should be: should pprint be producing platform specific line endings or not? Either way, the test should confirm the expected behaviour.



 Comments   
Comment by Andy Fingerhut [ 10/Dec/12 1:57 AM ]

Most likely this should be closed as a duplicate of CLJ-1076. The symptoms sound the same, and CLJ-1076 has a patch for it that should fix the problem.

Comment by Mike Anderson [ 10/Dec/12 2:03 AM ]

Hi Andy - yes this looks like a duplicate, thanks for spotting. Should be closed.

Comment by Andy Fingerhut [ 10/Dec/12 11:45 AM ]

Duplicate of CLJ-1076





Generated at Sat May 25 12:19:29 CDT 2013 using JIRA 4.4#649-r158309.