From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92098 invoked by alias); 22 Nov 2017 21:27:06 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 92085 invoked by uid 89); 22 Nov 2017 21:27:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=remind, relationship X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Nov 2017 21:27:04 +0000 Received: from [10.9.9.211] (helo=mailfront11.runbox.com) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1eHcXt-0003N1-FC; Wed, 22 Nov 2017 22:27:01 +0100 Received: from 32.109.34.95.customer.cdi.no ([95.34.109.32] helo=localhost.localdomain) by mailfront11.runbox.com with esmtpsa (uid:757155 ) (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) id 1eHcXl-0001Gr-FQ; Wed, 22 Nov 2017 22:26:53 +0100 Subject: Re: Prompt on read To: kawa@sourceware.org, Helmut Eller References: From: Per Bothner Message-ID: <964c1080-8e56-e60f-a3cd-f14eb12a44be@bothner.com> Date: Wed, 22 Nov 2017 21:27:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-q4/txt/msg00038.txt.bz2 On 11/22/2017 12:31 AM, Helmut Eller wrote: > On Tue, Nov 21 2017, Per Bothner wrote: > >>> Despite that the prompt in line two is confusing, the line number in the >>> third prompt seems wrong. I would expect that read works basically like >>> read-line, >> >> Yes and no. read reads an S-expression, and there may be a many-to-many >> relationship between S-expressions and lines. A prompt is printed before >> each input line - > > If a prompt is printed before each input line, then why does calling > read-line not print a prompt? > >> however note it is possible for a procedure to change the >> prompt, for example to the empty string. (After having to remind myself how it all works ...) The interactive port does print a prompt at the beginning of line, if there is a prompt specified. However, the default prompt procedure depends on the "read state" (i.e. input-port-read-state). If the read-state is #\newline (which is the default) the default prompt string is empty (or actually null). The read procedures sets the read-state as it parses the S-expression. Now consider: $ bin/kawa console:use-jline=no #|kawa:1|# (define r1 (read)) #|kawa:2|# (4 5) #|kawa:2|# r1 (4 5) #|kawa:3|# Why is the line 2 prompt repeated? I'm still trying to figure that out, but it appears related to the fact that read doesn't read the entire line, only the "(4 5)". For example read followed by read-line to read the remainder of the line works as expected. #|kawa:3|# (define r2 (read)) (define l2 (read-line)) #|kawa:4|# (5 6) #|kawa:5|# r2 (5 6) #|kawa:6|# (write l2) "" #|kawa:7|# There are also some weirdness with console:use-jline=no (raw console read) vs console:use-jline=yes (read using jline input library). > You mean something like (fluid-let ((input-prompt1 "")) ...) or > something else? Hmm, that would work for me. That could work. > >> FWIW I can't come up with any valid use-case for explicitly calling >> read on an interactive port. The problem is error recovery. >> Enlighten me. > > Uhm, a REPL that wants to print its own prompt? In which case you'd override the default prompt. Or something like > > (format #t "Please enter a filename: ") > (open-output-file (read)) Here read-line makes sense but read is clearly wrong. -- --Per Bothner per@bothner.com http://per.bothner.com/