Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cl-format reuse the previous parameter

Is there a way to avoid duplicating the 1 in the following line using cl-format?

(cl-format true "line~p: ~d\n" 1 1)

like image 475
nha Avatar asked Oct 20 '25 17:10

nha


1 Answers

CL-USER> (format t "line~p: ~:*~d~%" 1)
line: 1
NIL
CL-USER> (format t "line~p: ~:*~d~%" 2)
lines: 2
NIL

(There's also ~n@* to go to the nth argument.)

22.3.7.1 Tilde Asterisk: Go-To

The next arg is ignored. ~n* ignores the next n arguments.

~:* backs up in the list of arguments so that the argument last processed will be processed again. ~n:* backs up n arguments.

[…] ~n@* goes to the nth arg, where 0 means the first one; n defaults to 0, so ~@* goes back to the first arg. Directives after a ~n@* will take arguments in sequence beginning with the one gone to.

like image 79
danlei Avatar answered Oct 24 '25 04:10

danlei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!