Re: [racket-users] How to discover a struct's interface without Dr Racket?

2021-10-30 Thread Brian Beckman
Here are some of my latest (failed) experiments:

#lang racket

(require (for-syntax racket/struct-info))
(require racket/pretty)

(struct foo (a b) #:transparent)

(displayln `("a foo object is transparent: I can see inside: \n  
(struct->vector (foo 1 2)) ~~> "
 ,(struct->vector (foo 1 2

(displayln `("syntax object is opaque I can't see inside: \n  
(struct->vector #'foo) ~~> "
 ,(struct->vector #'foo)))

;;; Why do two copies of the syntax display? (One copy
;;; is a side-effect. The other is a result).

;;; At expansion time, I can get some graphics in Dr-Racket for
;;; definition of foo, but I cannot get likewise 
;;; not into the definition of syntax. 
(begin-for-syntax
  (displayln 
   (extract-struct-info
(syntax-local-value
 #'foo  ; #'syntax

;;; But the access procedures for #'syntax are known!?!? (I just
;;; happen to know that there is a procedure named 'syntax-position';
;;; my whole issue is in trying to find out the list of all
;;; procedures defined in the system when the syntax type is created!)

(syntax-position #'42)

;;; Whereas #'foo is known in this module scope,
;;; (syntax struct:foo) is not known! Looks like the shorthand
;;; #'whatever for making a syntax object is known, but the longhand,
;;; presumably (syntax 'whatever), is not known.

(begin-for-syntax
  (displayln 
   (extract-struct-info
(syntax-local-value
 #'syntax



Welcome to DrRacket, version 8.2 [cs].
Language: racket, with debugging; memory limit: 128 MB.
(.# 
.# 
.# 
(.# 
.#) (#f #f) #t)
. . 
../../../../../../usr/share/racket/pkgs/errortrace-lib/errortrace/stacktrace.rkt:690:2:
 
extract-struct-info: contract violation
  expected: struct-info?
  given: #
> 

On Friday, October 29, 2021 at 4:10:37 PM UTC-7 Siddhartha Kasivajhula 
wrote:

> I was able to find this interface 
> ,
>  
> but it doesn't quite provide the same information. E.g. (struct-type-info 
> struct:foo)
>
> The ability to "introspect" values in a shell (or in the application) is 
> useful in languages like python (e.g. dir(object) tells you what methods 
> it provides, help(anything) gives you the interface/function signature, 
> docstrings, etc.). I haven't seen this style emphasized in Racket 
> documentation, and that may be because racket isn't object-oriented by 
> default as python is, so that there often isn't a single object 
> encapsulating all of this information.
>
> But all the same, if there are analogous facilities in racket, like the 
> kind Brian asked about, I'd love to know as well.
>
>
> On Fri, Oct 29, 2021 at 3:14 PM Brian Beckman  wrote:
>
>> Well, as I understand it, a struct (usually? always?), #:transparent or 
>> not, when declared, defines symbols that are meant to be visible in the 
>> current scope, so (struct foo (a b)) defines foo #|constructor|#, foo? 
>> #|instance-predicate|# foo-a and foo-b #|data accessors|# , that I can call 
>> on instances:
>>
>> (struct foo (a b))
>> (let ([my-foo (foo 42 37)]
>>(list (foo? my-foo) 
>>  (foo-a my-foo) 
>>  (foo-b my-foo)))  ~~>  '(#t 42 37)
>>
>> I would like, given only the symbol foo referring to the struct type 
>> itself, to discover (at least) the list of procedures foo?, foo-a, foo-b, 
>> plus anything else the author of foo (the type) wants me to see.
>> 
>>
>> On Fri, Oct 29, 2021 at 1:45 PM John Clements  
>> wrote:
>>
>>> In the text below, you refer to the “public” interface. Can I ask what 
>>> you mean by “public” in this context?
>>>
>>> John
>>>
>>> > On Oct 29, 2021, at 11:16 AM, Brian Beckman  
>>> wrote:
>>> > 
>>> > I believe that run time will be the most plausible use case. I may 
>>> write macros that refer to struct-procedure names at macro-writing time, 
>>> but I don't expect to invoke the struct procedures at macro-expansion time. 
>>> My primary issue is "discoverability:" how can I find out the interface of 
>>> any struct?
>>> > 
>>> > On Thursday, October 28, 2021 at 1:00:15 PM UTC-7 jackh...@gmail.com 
>>> wrote:
>>> > Are you intending to use the struct procedure names at compile time 
>>> (such as in a macro) or runtime?
>>> > 
>>> > On Tuesday, October 26, 2021 at 5:02:46 PM UTC-7 bc.be...@gmail.com 
>>> wrote:
>>> > I understand why structs are opaque, by default, but I want to 
>>> discover the public interface of some struct type, that is, a list of the 
>>> procedures defined by the struct.
>>> > 
>>> > Here is an example. Suppose I want to find out all the procedures 
>>> defined on an instance of the syntax struct
>>> > 
>>> > #'42
>>> > 
>>> > Dr. Racket shows an expander clicky that shows some formatted 
>>> information inside the instance :
>>> > 
>>> > 
>>> > 
>>> > Uncapitializing the names in the display reveals the interface:
>>> > 
>>> > (syntax-position #'42) ~~> 790
>>> > (syntax-span #'42) 

Re: [racket-users] Adding keybindings to debug

2021-10-30 Thread David Storrs
The menu strings get very fussy, so check that you entered it exactly
right, and do a very simple one to start. That's the usual cause in my
experience.

On Sat, Oct 30, 2021, 7:25 AM Mike Engelhart  wrote:

> On Mac OS I tried adding keyboard shortcuts using the linked Apple support
> document to allow for comment/uncomment bindings in DrRacket and it doesn't
> work (at least on Mac OS Monterey).  One thing I noticed is that if you go
> back to System Preferences->Keyboard->Shortcuts->App Shortcuts and look at
> DrRacket under App Shortcuts, unlike other Mac OS apps in the list, it only
> shows the name DrRacket but doesn't show any of the shortcuts you've added.
>
>
> On Sat, Oct 30, 2021 at 6:37 AM Laurent  wrote:
>
>> On Fri, Oct 29, 2021 at 10:47 PM James Zollinger 
>> wrote:
>>
>>> Thank you both for the thoughtful answers. I will take a look at the
>>> quickscript you sent, Laurent. The mac keyboard shortcut is a great
>>> feature. Makes me wonder about buying a mac again after quite a few years.
>>> (I use debian as my daily driver, at least for development.)
>>
>>
>> Apparently it should be possible to do the same thing for Debian,
>> depending on your window manager, with some caveats:
>>
>> https://askubuntu.com/questions/107849/can-i-assign-custom-keyboard-shortcuts-for-menu-items-in-applications
>>
>>
>>> If anyone out there knows how to deal with context menus
>>> programmatically, please share.
>>>
>>
>> The code of the debug-tool should be changed to make these reachable from
>> the outside with a define/public. Somewhere around here:
>>
>> https://github.com/racket/drracket/blob/b74dc3bc65b4843db0c2b381161fa9e8d85d230d/drracket/gui-debugger/debug-tool.rkt#L375
>> but it's a little intricate because a set of specialized menu items are
>> created after right-clicking when in debug mode.
>>
>> Another possibility would be to simulate the mouse clicks, but that seems
>> rather hacky and error-prone.
>>
>> --
>> 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/CABNTSaGiZ%2BbZirkyrtTScbVg5EK4reJw-JtoK3%2BTh5%3DCW7SiDQ%40mail.gmail.com
>> 
>> .
>>
> --
> 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/CAGE%3DCnJ7FfvOOkk0_Q2Ch4kinJx%2BM5MEBwPYDcqNSFqLWQxOSQ%40mail.gmail.com
> 
> .
>

-- 
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/CAE8gKodhBXn_qntvi5qzQkYwjQnwA_c2uGhHJem-SSL0dmLm8g%40mail.gmail.com.


Re: [racket-users] Adding keybindings to debug

2021-10-30 Thread Mike Engelhart
On Mac OS I tried adding keyboard shortcuts using the linked Apple support
document to allow for comment/uncomment bindings in DrRacket and it doesn't
work (at least on Mac OS Monterey).  One thing I noticed is that if you go
back to System Preferences->Keyboard->Shortcuts->App Shortcuts and look at
DrRacket under App Shortcuts, unlike other Mac OS apps in the list, it only
shows the name DrRacket but doesn't show any of the shortcuts you've added.


On Sat, Oct 30, 2021 at 6:37 AM Laurent  wrote:

> On Fri, Oct 29, 2021 at 10:47 PM James Zollinger  wrote:
>
>> Thank you both for the thoughtful answers. I will take a look at the
>> quickscript you sent, Laurent. The mac keyboard shortcut is a great
>> feature. Makes me wonder about buying a mac again after quite a few years.
>> (I use debian as my daily driver, at least for development.)
>
>
> Apparently it should be possible to do the same thing for Debian,
> depending on your window manager, with some caveats:
>
> https://askubuntu.com/questions/107849/can-i-assign-custom-keyboard-shortcuts-for-menu-items-in-applications
>
>
>> If anyone out there knows how to deal with context menus
>> programmatically, please share.
>>
>
> The code of the debug-tool should be changed to make these reachable from
> the outside with a define/public. Somewhere around here:
>
> https://github.com/racket/drracket/blob/b74dc3bc65b4843db0c2b381161fa9e8d85d230d/drracket/gui-debugger/debug-tool.rkt#L375
> but it's a little intricate because a set of specialized menu items are
> created after right-clicking when in debug mode.
>
> Another possibility would be to simulate the mouse clicks, but that seems
> rather hacky and error-prone.
>
> --
> 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/CABNTSaGiZ%2BbZirkyrtTScbVg5EK4reJw-JtoK3%2BTh5%3DCW7SiDQ%40mail.gmail.com
> 
> .
>

-- 
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/CAGE%3DCnJ7FfvOOkk0_Q2Ch4kinJx%2BM5MEBwPYDcqNSFqLWQxOSQ%40mail.gmail.com.


Re: [racket-users] Adding keybindings to debug

2021-10-30 Thread Laurent
On Fri, Oct 29, 2021 at 10:47 PM James Zollinger  wrote:

> Thank you both for the thoughtful answers. I will take a look at the
> quickscript you sent, Laurent. The mac keyboard shortcut is a great
> feature. Makes me wonder about buying a mac again after quite a few years.
> (I use debian as my daily driver, at least for development.)


Apparently it should be possible to do the same thing for Debian, depending
on your window manager, with some caveats:
https://askubuntu.com/questions/107849/can-i-assign-custom-keyboard-shortcuts-for-menu-items-in-applications


> If anyone out there knows how to deal with context menus programmatically,
> please share.
>

The code of the debug-tool should be changed to make these reachable from
the outside with a define/public. Somewhere around here:
https://github.com/racket/drracket/blob/b74dc3bc65b4843db0c2b381161fa9e8d85d230d/drracket/gui-debugger/debug-tool.rkt#L375
but it's a little intricate because a set of specialized menu items are
created after right-clicking when in debug mode.

Another possibility would be to simulate the mouse clicks, but that seems
rather hacky and error-prone.

-- 
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/CABNTSaGiZ%2BbZirkyrtTScbVg5EK4reJw-JtoK3%2BTh5%3DCW7SiDQ%40mail.gmail.com.