Re: [racket-users] Re: Concise way to get completions for Racket code?

2018-02-13 Thread nocheroot
This is definitely pointing me where I want to go, thanks.

#lang racket

(let ([n (make-base-namespace)])
  (parameterize ([current-namespace n])
(eval '(define oneplusone (+ 1 1)))
(filter (lambda (y) (regexp-match #px"^one" y))
(map (lambda (x) (symbol->string x)) (namespace-mapped-symbols 
n)



On Tuesday, February 13, 2018 at 6:39:49 AM UTC-6, William G Hatch wrote:
>
> >On Wednesday, February 7, 2018 at 5:12:00 PM UTC-6, noch...@gmail.com 
> wrote: 
> >> 
> >> My google-fu is failing me today.  Is there a concise way in Racket to 
> >> request possible completions for some Racket code? 
>
> Another function that may be useful for you is 
> `namespace-mapped-symbols`.  The readline library uses this to provide 
> completion in the repl. 
>

-- 
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: Concise way to get completions for Racket code?

2018-02-09 Thread nocheroot
Will your omni-completion also work in Vim?

On Friday, February 9, 2018 at 3:52:30 PM UTC-6, HiPhish wrote:
>
> Thank you for finding that. I have used your snippet to add 
> omni-completion to
> Neovim now. I need to file down some rough patches before I make it a 
> plugin,
> but it works. Not as useful as having proper semantic completion would have
> been, it does not include identifiers from the current module and includes 
> all
> sorts of identifiers that haven't been imported. Still, better than 
> nothing I
> guess.
>
>
>
> 
>
>
> 
>
>
> On Thursday, February 8, 2018 at 11:28:21 PM UTC+1, noch...@gmail.com 
> wrote:
>>
>> 
>>
>

-- 
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: Concise way to get completions for Racket code?

2018-02-08 Thread nocheroot


In case anyone else finds this helpful.  I poked around the DrRacket source 
and found text:get-completions/manuals.  This gave me a thread to pull.  
After more googling, docs, and reading more source I think I can answer my 
own question.


The short answer is no.


The long answer is sort of.  If I am understanding correctly, Racket does 
not provide the capability to directly look up lexical scope aware 
completions.  But, text:get-completions/manuals in framework can be used to 
look up a list of keywords in documented exports.  That list can then be 
searched for an applicable completion for a partial word.


Not sure why I failed to find this yesterday.


https://docs.racket-lang.org/framework/Text.html?q=text%3Aget-completions%2Fmanuals#%28def._%28%28lib._framework%2Fmain..rkt%29._text~3aget-completions%2Fmanuals%29%29


Here is a quick and dirty example.  There is probably a much better way to 
do this, but I'm still learning.  I'll settle for something that just works 
for now.


#lang racket
(require framework)

(filter (lambda (x) (regexp-match #px"^def" x)) 
(text:get-completions/manuals #f))




On Wednesday, February 7, 2018 at 5:12:00 PM UTC-6, noch...@gmail.com wrote:
>
> My google-fu is failing me today.  Is there a concise way in Racket to 
> request possible completions for some Racket code?  For example, in 
> powershell I can ask System.Management.Automation.CommandCompletion for 
> possible completions of the powershell code "ConvertTo-Json -"  like this:
>
> $cmd = "ConvertTo-Json -"
> $ret = 
> [System.Management.Automation.CommandCompletion]::MapStringInputToParsedInput($cmd,
>  
> $cmd.Length)
>
> $candidates = 
> [System.Management.Automation.CommandCompletion]::CompleteInput(
> $ret.Item1,
> $ret.Item2,
> $ret.Item3,
> $null,
> [System.Management.Automation.PowerShell]::Create()
> ).CompletionMatches
>
> $candidates | ForEach-Object {
> [pscustomobject]@{
> CompletionText = $_.CompletionText
> ResultType = $_.ResultType.ToString()
> ToolTip = $_.ToolTip
> }
> }
>
> Outputs (depending on system, powershell and .net version):
> CompletionText   ResultTypeToolTip 
> --   ----- 
> -InputObject ParameterName [Object] InputObject
> -Depth   ParameterName [int] Depth 
> -CompressParameterName [switch] Compress   
> -Verbose ParameterName [switch] Verbose
> -Debug   ParameterName [switch] Debug  
> -ErrorAction ParameterName [ActionPreference] ErrorAction  
> -WarningAction   ParameterName [ActionPreference] WarningAction
> -InformationAction   ParameterName [ActionPreference] InformationAction
> -ErrorVariable   ParameterName [string] ErrorVariable  
> -WarningVariable ParameterName [string] WarningVariable
> -InformationVariable ParameterName [string] InformationVariable
> -OutVariable ParameterName [string] OutVariable
> -OutBuffer   ParameterName [int] OutBuffer 
> -PipelineVariableParameterName [string] PipelineVariable   
>
>

-- 
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] Concise way to get completions for Racket code?

2018-02-07 Thread nocheroot
My google-fu is failing me today.  Is there a concise way in Racket to 
request possible completions for some Racket code?  For example, in 
powershell I can ask System.Management.Automation.CommandCompletion for 
possible completions of the powershell code "ConvertTo-Json -"  like this:

$cmd = "ConvertTo-Json -"
$ret = 
[System.Management.Automation.CommandCompletion]::MapStringInputToParsedInput($cmd,
 
$cmd.Length)

$candidates = 
[System.Management.Automation.CommandCompletion]::CompleteInput(
$ret.Item1,
$ret.Item2,
$ret.Item3,
$null,
[System.Management.Automation.PowerShell]::Create()
).CompletionMatches

$candidates | ForEach-Object {
[pscustomobject]@{
CompletionText = $_.CompletionText
ResultType = $_.ResultType.ToString()
ToolTip = $_.ToolTip
}
}

Outputs (depending on system, powershell and .net version):
CompletionText   ResultTypeToolTip 
--   ----- 
-InputObject ParameterName [Object] InputObject
-Depth   ParameterName [int] Depth 
-CompressParameterName [switch] Compress   
-Verbose ParameterName [switch] Verbose
-Debug   ParameterName [switch] Debug  
-ErrorAction ParameterName [ActionPreference] ErrorAction  
-WarningAction   ParameterName [ActionPreference] WarningAction
-InformationAction   ParameterName [ActionPreference] InformationAction
-ErrorVariable   ParameterName [string] ErrorVariable  
-WarningVariable ParameterName [string] WarningVariable
-InformationVariable ParameterName [string] InformationVariable
-OutVariable ParameterName [string] OutVariable
-OutBuffer   ParameterName [int] OutBuffer 
-PipelineVariableParameterName [string] PipelineVariable   

-- 
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] Quick regexp question

2018-02-02 Thread nocheroot
It is nice.  I'll have to play with this as well.  Thanks again everyone.

On Friday, February 2, 2018 at 5:49:15 PM UTC-6, johnbclements wrote:
>
>
>
> > On Feb 2, 2018, at 3:21 PM, Matthew Butterick  > wrote: 
> > 
> > 
> >> On Feb 2, 2018, at 10:23 AM, 'John Clements' via Racket Users <
> racket...@googlegroups.com > wrote: 
> >> 
> >> This macro gets the names in much closer to the corresponding patterns 
> than matching by index, but it doesn’t actually embed the names into the 
> regexp. 
> > 
> > 
> > If you like keeping the names and patterns together, you could also 
> create an association list of the names and subpatterns, and iterate: 
> > 
> > #lang racket 
> > 
> > (define msg "2018-02-02T11:26:34 someuser some-computername01 
> 233.194.20.110 something broke") 
> > (with-input-from-string msg 
> >  (thunk 
> >(for/hash ([(name pat) (in-dict '((date . "[-\\dT:]+") 
> >  (username . "\\w+") 
> >  (hostname . "[-\\w\\d]+") 
> >  (ip . "[\\d\\.]+") 
> >  (message . ".+")))]) 
> >  (values name (car (regexp-match (pregexp pat) 
> (current-input-port))) 
>
> Oh, that’s nice. 
>
> In fact, I’ll tell you what I *really* like about that; it could radically 
> simplify the irritating process of debugging regexps by breaking them in 
> various places to perform a binary search; you could instead provide a nice 
> error message specifying exactly which part of the regexp failed to match. 
>
> One thing to be aware of is that you’d need to make sure that your regexp 
> still works without backtracking. If you broke #px”.*abc” into #px”.*” and 
> #px”abc”, it wouldn’t mean the same thing any more. 
>
> John 
>
> > 
> > 
> > '#hash((message . #" something broke") 
> >   (date . #"2018-02-02T11:26:34") 
> >   (username . #"someuser") 
> >   (hostname . #"some-computername01") 
> >   (ip . #"233.194.20.110")) 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
>

-- 
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] Quick regexp question

2018-02-02 Thread nocheroot
In the long run this is probably better than what I wanted.  Thank you

On Friday, February 2, 2018 at 12:23:48 PM UTC-6, johnbclements wrote:
>
> Not sure if this gets you as far as you want, but you could use a macro to 
> associate names with paren-wrapped items: 
>
> #lang racket 
>
> (define-syntax re-match 
>   (syntax-rules () 
> [(_ str re name ...) 
>  (match str 
>[(regexp re (list _ name ...)) 
> (list (list (quote name) name) ...)])])) 
>
> (define msg "2018-02-02T11:26:34 someuser some-computername01 
> 233.194.20.110 something broke") 
>
> (re-match msg 
>   #px"^([-\\dT:]+)\\s(\\w+)\\s([-\\w\\d]+)\\s([\\d\\.]+)\\s(.+)$" 
>   date username hostname ip message) 
>
> … produces: 
>
> '((date "2018-02-02T11:26:34") 
>   (username "someuser") 
>   (hostname "some-computername01") 
>   (ip "233.194.20.110") 
>   (message "something broke”)) 
>
>
> This macro gets the names in much closer to the corresponding patterns 
> than matching by index, but it doesn’t actually embed the names into the 
> regexp. 
>
> John Clements 
>
>
> > On Feb 2, 2018, at 10:01 AM, noch...@gmail.com  wrote: 
> > 
> > Sorry if I've missed this in the documentation, but I don't see it, and 
> it is starting to bother me. 
> > 
> > In Powershell. Python, and Splunk I'm able to perform automatic field 
> extraction on strings and access the values of fields by name.  Is there a 
> way to do this in Racket?  Of course, pairing matches with field names by 
> index is an option, but not as convenient in some situations. 
> > 
> > Take string "2018-02-02T11:26:34 someuser some-computername01 
> 233.194.20.110 something broke" as a trivial example. 
> > 
> > Powershell: 
> > "2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 
> something broke" -match 
> "^(?[\d\-T:]+)\s(?\w+)\s(?[\w\-\d]+)\s(?[\d\.]+)\s(?.+)$"
>  
> | Out-Null 
> > 
> > $matches.date 
> > $matches.username 
> > $matches.hostname 
> > $matches.IP 
> > $matches.message 
> > 
> > Python: 
> > m = 
> re.match("^(?P[\d\-T:]+)\s(?P\w+)\s(?P[\w\-\d]+)\s(?P[\d\.]+)\s(?P.+)$",
>  
> "2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 something 
> broke") 
> > 
> > m['Date'] 
> > m['Username'] 
> > m['Hostname'] 
> > m['IP'] 
> > m['Message'] 
> > 
> > Both output: 
> > 
> > 2018-02-02T11:26:34 
> > someuser 
> > some-computername01 
> > 233.194.20.110 
> > something broke 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
>

-- 
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] Quick regexp question

2018-02-02 Thread nocheroot
Sorry if I've missed this in the documentation, but I don't see it, and it 
is starting to bother me.

In Powershell. Python, and Splunk I'm able to perform automatic field 
extraction on strings and access the values of fields by name.  Is there a 
way to do this in Racket?  Of course, pairing matches with field names by 
index is an option, but not as convenient in some situations.

Take string "2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 
something 
broke" as a trivial example.

Powershell:
"2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 something 
broke" -match 
"^(?[\d\-T:]+)\s(?\w+)\s(?[\w\-\d]+)\s(?[\d\.]+)\s(?.+)$"
 
| Out-Null

$matches.date
$matches.username
$matches.hostname
$matches.IP
$matches.message

Python:
m = re.match(
"^(?P[\d\-T:]+)\s(?P\w+)\s(?P[\w\-\d]+)\s(?P[\d\.]+)\s(?P.+)$"
, "2018-02-02T11:26:34 someuser some-computername01 233.194.20.110 something 
broke")

m['Date']
m['Username']
m['Hostname']
m['IP']
m['Message']

Both output:

2018-02-02T11:26:34
someuser
some-computername01
233.194.20.110
something broke

-- 
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.