The first thing to realize is that "you" cannot do this, but you might be able to write CL-conformant code that does it for you. But the READ function won't do it by itself. It's not part of READ's contract, which silently eats Newlines without counting them for you.
You might consider some readtable magic, changing Newline to a non-non-breaking macro char that returns nothing but maintains a count somewhere, except such hackery would miss line breaks inside strings, #|comments|#, probably also ;regular comments, and escaped newlines inside symbol names (UGH).
Rather than writing your own entire READ function, if the source is a regular static file that can be reopened multiple times, wrtie a simple alternative MY-READ function that calls FILE-POSITION before calling READ and returns both a multiple values. Converting a character FILE-POSITION into a line number, when and if necessary, can be accomplished by reopening the file and reading characters until the desired FILE-POSITION counting line breaks along the way. Taking care to use the same external-format avoids the difficulty of multi-byte characters and the possibility that FILE-POSITION does not necessarily increment by 1 for each char. It is only guaranteed to increase monotonically.
On Wed, Jun 26, 2019 at 9:19 AM Alexandre Rademaker arademaker@gmail.com wrote:
The “read” function makes really easy to read a bunch of s-expressions from a file, but how can I keep track of the line number where the expressions were in the file?
Any ideia?
Alexandre Sent from my iPhone