[racket-users] Strange readline/racket-mode behavior

2021-09-24 Thread Winston Weinert
Hey everyone,

I was working on a procedure to prompt the user for confirmation and found
something a bit strange - it did not appear to read for input when usingt
"racket -i" or in the Emacs Racket REPL buffer.  Here is the code:

(define (yn #:read-one-char? [read-one-char? #f])
  (display "y/n: ")
  (flush-output (current-output-port))
  (if read-one-char?
  (match (read-char)
[(or #\y #\Y) #t]
[m #f])
  (match (read-line)
[(or "y" "Y") #t]
[m #f])))

Regardless if I use read-char or read-line and type y or Y, the behavior seeims
similar, each of the match's second clause is followed because (read-char)
returns #\newline whereas read-line returns "" (empty string).

I mentioned this strange behavior on the Libera chat and got an enlightening
response from tonyg outlining what is happening:

> at the repl, if you type "(read-char)" and press enter, the reader sees ( r e
> a d - c h a r ) NEWLINE. When it gets to the close-parenthesis, it executes
> the expression, which reads the NEWLINE character and returns. Similar for
> read-line, where it sees NEWLINE and returns an empty line
>
> try typing (list (read-line) (read-line))

I can confirm tonyg's solution works.  The (list (read-char) (read-char)) also
appears to work, though one always has to type a final newline to send the
line-buffered input.

The behavior feels very surprising and took me a bit of time to figure out,
even then I didn't really understand it so I had to ask for help.  Can this
behavior be changed in a future release?  Is a reasonable request or could this
break a lot of code?  If this could break stuff, is it worth doing changing it
anyway, so the behavior is less surprising?  I hope to understand if it's
agreeable to make a PR for this change before investing the time.

Keep on Racketing!

Winston Weinert
winny.tech

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20210924190134.mjxttwqtgeunjbus%40ml1.net.


[racket-users] Descriptions, URLs, and READMEs for racket org projects

2018-05-27 Thread Winston Weinert
I was perusing the Racket organization GitHub and noticed many of the repos 
do not have descriptions, URLs, and READMEs.

I think this would be nice if each Racket package had a README with a link 
to the documentation (on r-l.org) and maybe a copy-paste from the 
scribblings of its synopsis.

Would PRs for this sort of thing be welcome? I am not familiar with how the 
various repos are managed, and don't want to create needless noise :)

Best,
Winston Weinert

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Search the Racket package catalog on the command line

2018-05-20 Thread Winston Weinert
Is there a way to search the Racket package catalog from the command line?

I found "raco pkg catalog-show --all" lists all entries, but it appears to 
take some time, and requires some extra processing to search by name 
properly (such as using a script to parse by entry, and match against the 
name field, and show matches).

Is there a better way?

Thanks,
Winston Weinert

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Typed Racket guard a binding with an error

2016-12-12 Thread Winston Weinert
Thanks. I wrote a rudimentary syntax transformer, but really I don't know the 
best way to work around this -- and I'm not very proficient with syntax 
transformers. I could put all of my code which I would prefer to be top level 
in a procedure/let context, but I don't really think this is the solution I'm 
looking for.

For example, I want to put some example data read by my port->list helper 
procedure in the top level for experimenting, but I'm sure there are more 
serious use cases for my issue.

Here's a very basic solution I just came up with. Any ideas would be 
appreciated:

#lang typed/racket

(define-syntax guard
  (syntax-rules ()
[(_ a b)
 (let ()
   (unless (a b)
 (error "guard failed"))
   b)]))

(define ls (port->list read (open-input-string "1 2 3 4")))
(for ([n (guard (λ (ls) (andmap number? ls)) ls)])
  (displayln (* n n)))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Typed Racket guard a binding with an error

2016-12-12 Thread Winston Weinert
Hi, the following code listing gives me this TR error: 

; /home/winston/code/practice/snippets/tr.rkt:7:16: Type Checker: type mismatch
;   expected: Number
;   given: Any
;   in: n
; /home/winston/code/practice/snippets/tr.rkt:7:18: Type Checker: type mismatch
;   expected: Number
;   given: Any
;   in: n
; Type Checker: Summary: 2 errors encountered


How do I fix this type guard?

Here is the code listing:

#lang typed/racket

(define ls (port->list read (open-input-string "1 2 3 4")))
(unless (andmap number? ls)
  (error "ls not read correctly"))
(for ([n ls])
  (displayln (* n n)))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: How to change text alignment in a text-field% and how to make text-field% read-only but still copy-able

2016-12-03 Thread Winston Weinert
> Use the lock method:
> 
>(send e lock #t)


This works perfectly. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: How to change text alignment in a text-field% and how to make text-field% read-only but still copy-able

2016-12-03 Thread Winston Weinert
I managed to resolve the alignment question with the following lines:

(define e (send my-text-field get-editor))
(send e auto-wrap #t)
(send e set-paragraph-alignment 0 'center)

However, I'm still at a loss how to make the text-field% read-only yet 
selectable.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How to change text alignment in a text-field% and how to make text-field% read-only but still copy-able

2016-12-03 Thread Winston Weinert
I didn't see a way to make the text in a text-field% right or center aligned. 
There was some talk about using the set-paragraph-alignment on the 
text-field%'s editable<%> (get-editor), but this didn't appear to work for me.

Also, I noticed if one sets the text-field%'s enabled to #f, it makes the text 
read only, but is not selectable. I also noticed the editable<%> has two 
related methods: can-delete? and can-insert?.

My first thought was to create a subclass of text% and change the text-field%'s 
editor<%>, but there doesn't appear to be a way to change the editor<%>.

How should I obtain the desired behavior? Is there a control more suitable for 
this task? Or am I half-way there?

Best,
Winston Weinert

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.