[racket-users] Re: github for third-party racket packages

2018-05-26 Thread HiPhish
I personally use GitLab over GitHub for various reasons, but for the 
purpose of this topic they are both interchangeable. Git is a decentralized 
system, so it doesn't really matter what you host it on, you could even 
host the project on some potato connected to the internet using a piece of 
wire.

There are basically two ways to view GitHub: as just a host for your code 
and as a platform for managing your project. If you only want to use it as 
a host it's no different from any other Git platform, but you are on your 
own when it comes to managing issues, patches and so on. If you want to use 
it to manage your project, then people who want to contribute will need a 
GitHub account. This is generally not a problem since pretty much everyone 
has one at this point, but keep in mind that the GitHub web interface does 
require non-free JavaScript (GitLab does not have this issue, and you can 
use your GitHub account with GitLab):
https://www.gnu.org/software/repo-criteria-evaluation.html

Other than that the workflow is pretty smooth and I have no complaints. It 
has some nice features like turning issue numbers into links, Markdown 
syntax and so on.

Integration with the Racket package management is no issue either. The web 
interface is aware of Git and works with any hosting service. I personally 
prefer to have the source code in a sub-directory of the project rather 
than in the root, and Racket supports this feature as well, like this:
https://gitlab.com/HiPhish/MsgPack.rkt
https://pkgs.racket-lang.org/package/msgpack

As for projects you don't want to publish, last time I checked you needed a 
paid GitHub account for that. GitLab offers private repositories for free, 
but it may be limited to a certain number and certain size, I don't know.

On Wednesday, May 23, 2018 at 8:51:16 PM UTC+2, Neil Van Dyke wrote:
>
> I'm thinking of moving all my open source third-party Racket packages to 
> GitHub, and had some questions, for other third-party developers... 
>
> 1. How do third-party developers of polished Racket packages like using 
> GitHub?  (Example questions... What friction is there still, to rapidly 
> making a change and a new release that appears in the Racket package 
> catalog?  Do you know whether being on GitHub imposes extra work over 
> non-GitHub for some things?  With GitHub, is there more work to go 
> through issue reports and pull requests, and process within the Web 
> site, because it happens to be convenient or in pursuit of metrics, as 
> opposed to receiving issue reports limited to ones people felt were 
> important enough to email you about privately?  How do you deal with 
> using GitHub for SCM of non-commercial stuff that you're not ready to 
> release?  Noticed any signs that GitHub might not always be as 
> warm-fuzzy, or have any unease about implicitly encouraging other people 
> to use it?) 
>
> 2. Has anyone automated migrating a history of Racket package releases 
> to Git (or to GitHub, specifically)?  (Rather than converting to Git 
> from a different SCM system, I'd be converting a history of release 
> packages from pre-PLaneT, PLaneT, and the current package system, and 
> want to have version tagging/labeling/naming happen.  I'm not sure it's 
> a good idea, since files were shuffled around within packages over the 
> last 17 years, for various reasons, but I'd like a sense of how much 
> work it would be.  An alternative, which I suspect is what I'll end up 
> doing if I move at all, is just to put the source from each last release 
> in Git, and not try to capture the history before that.) 
>
> Background: My Racket open source releases are in minimal maintenance 
> mode, while I do a career shift, from gov't independent consulting, to 
> academic/non-profit/industry research/engineering/policy.  Also, my 
> Racket package release workflow is friction-y for the last few years, so 
> every urgent quick release in response to some issue someone is facing 
> feels like more work than it should be, and so I haven't tried to 
> release various unreleased packages that have been sitting around for 
> years, and I ceased the occasional evening/weeking whipping up of a new 
> package intended for release.  My top priority for my Racket open source 
> code is to continue to provide support for packages that I've already 
> released, and my second priority is to be in a position that I could 
> easily ramp back up releasing polished new stuff at later date. 
>
>

-- 
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] Sequences in Typed Racket?

2018-04-23 Thread HiPhish
The adapter submodule does not work, I get the following error (in both 
typed and untyped Racket):

fib.rkt:9:0: module: no #%module-begin binding in the module's language
  in: (module adapter racket/stream (provide stream-first stream-rest 
(rename-out (stream-cons* stream-cons))) (define (stream-cons* make-first 
make-rest/seq) (stream-cons (make-first) (sequence->stream 
(make-rest/seq)

If I understand your code correctly, the idea is to define `fibonacci` as a 
stream which returns a stream of Fibonacci numbers, correct? Won't that 
incur a performance loss when used like that in a for-loop if the user does 
not wrap it up in `in-stream`? The idea of `in-fibonacci` was to have a 
form which can be used in a foor-loop the same way `in-naturals` can be. 
Except `in-fibonacci` would have an optional argument at which Fibonacci 
number to start counting.


On Sunday, April 22, 2018 at 10:48:12 AM UTC+2, Philip McGrath wrote:
>
> I hope there's a better way, but this works. The adapter submodule is 
> needed because the normal `stream-cons` is a macro that expands into some 
> private things that don't have types, and it requires that the rest 
> expression produce a stream, not just any sequence. Note also, if you 
> haven't worked with `racket/stream` before, that the arguments to the 
> normal `stream-cons` are evaluated lazily.
>

-- 
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] Sequences in Typed Racket?

2018-04-22 Thread HiPhish
Hello Racketeers,

I have been playing around with the `math/number-theory` package and I 
wanted to use a `for`-loop of Fibonacci numbers. I had to write something 
like

(for ([i (in-naturals)])
  (define fib (fibonacci i))
  ...)

So I thought it would be nice to have an `in-fibonacci` sequence. According 
to the Racket reference [1] one can implement a custom sequence using 
structure type properties, but according to the Typed Racket guide [2] 
structure type properties are not supported in Typed Racket. Is there any 
other way to get `in-fibonacci` into the module or should I just live 
without it?

[1] https://docs.racket-lang.org/reference/sequences.html?q=sequences
[2] 
https://docs.racket-lang.org/ts-guide/caveats.html#%28part._.Unsupported_features%29

-- 
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: RacketCon 2018 Website

2018-04-20 Thread HiPhish
Yeah, those fancy things are an accessibility nightmare. When I zoom in in 
FireFox the line breaks are fine, but between 110% and 200% zoom factor the 
text actually gets smaller when zooming in, and beyond 200% it gets larger 
again.

As for screen readers, I am no ARIA expert, but from what I (think I) know, 
wrapping the ASCII art in a span with the "aria-hidden" attribute (either 
in a span or div, since those are semantically invisible) should hide them 
from screen readers so that listeners are not bombarded with seemingly 
random ASCII characters. As a substitute a label can be added to the 
enclosing . I'm thinking about something like in this StackOverflow 
answer: https://stackoverflow.com/a/26032207

-- 
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: Why is there a space in the path to the Racket application on MacOSX?

2018-04-01 Thread HiPhish
I don't know where you are going with your book, but are you sure forcing 
people to use the command-line interface is a good idea? Racket can be 
fully used through the GUI (even managing packages can be done through 
DrRacket). I agree with explaining both DrRacket and raco, but why can't 
users just pick the one they are more comfortable with and ignore the other 
(and maybe come back later to it)?

I think the biggest problem is that so many people have very low computer 
literacy. You will never see a book or web tutorial explaining concepts 
like clicking, right-clicking, drag or double-clicking because those 
are so essential to using a computer. However, few people know how to use 
the CLI, even though it allows you to automate and combine things in a way 
a GUI cannot. You don't even have to be a programmer to find the CLI useful.

On Sunday, April 1, 2018 at 6:57:46 PM UTC+2, Stephen Smith wrote:
>
> 2. @HiPhish: "Users should learn the command-line first". Although I agree 
> with this in almost any other context, my book is for people who have never 
> programmed before. So they will be learning the command-line and GUI at the 
> same time (they have no choice in the matter ;-). In my opinion though, 
> raco is an essential command line tool to teach new Racketeers so at least 
> in my case the GUI alone will not suffice. And my book is not really a 
> "Racket" book per se - Racket is just a tool to achieve the end goal. Which 
> probably requires further explanation ...
>

-- 
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: Why is there a space in the path to the Racket application on MacOSX?

2018-03-31 Thread HiPhish
BTW, on the topic of writing robust shell scripts, I always have a linter 
run over my scripts when I save them. I run Shellcheck automatically in 
Neovim using the Neomake plugin. The linter catches among other things 
missing quotations.

https://www.shellcheck.net/
https://github.com/neomake/neomake/

You can run Shellcheck manually over the CLI if you cannot set up your 
editor to do it automatically.

-- 
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: Why is there a space in the path to the Racket application on MacOSX?

2018-03-30 Thread HiPhish
The benefit is that it looks nicer on the eyes in a GUI. I presume OP is 
talking about the Racket installation you get off the Racket website, and 
that installation is targeted at GUI users. I myself prefer the 
command-line and I use Racket via Homebrew, so I never even come across 
this issue.

Visual appeal is also why Lisp languages use the hyphen as a separator in 
names, it looks nicer on the eye. The reason most languages use the 
underscore is because the hyphen would be interpreted as the binary minus 
operator. Fun fact: in his original Lisp paper McCarthy allowed for spaces 
in symbols and used commas as separators, see page 9 of this PDF:
http://www-formal.stanford.edu/jmc/recursive.pdf

On Friday, March 30, 2018 at 4:44:26 PM UTC+2, David K. Storrs wrote:
>
> I look at it the other way:  there are clear benefits to NOT having 
> names containing characters that need to be quoted, so any use of such 
> characters has an opportunity cost.  What benefit does the space 
> provide that outweighs that opportunity cost? 
>

-- 
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: Why is there a space in the path to the Racket application on MacOSX?

2018-03-29 Thread HiPhish
I think you are trying to solve the wrong problem. If people want to use a 
command-line tool they should know how to use the command line first. They 
don't have to know every arcane feature of the Bourne Shell, but knowing to 
escape spaces or quote strings is the bare minimum. Think about it like 
this: if you are trying to give someone directions you already assume they 
know how to drive a car, right? If you want to write a book on Racket, then 
focus on Racket. And if they cannot use the command-line they can still use 
the GUI tools.

On Thursday, March 29, 2018 at 9:51:07 PM UTC+2, Stephen Smith wrote:
>
> Authoring a new Racket book (targeting all platforms and non-programmers) 
> and having to tell users to quote paths with spaces to be able to use the 
> command-line tools seems distracting and an unnecessary complexity to 
> impose on them.
>

-- 
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] Splitting up a GUI source file?

2018-03-24 Thread HiPhish
Thank you for the paper. I had come across units several times, but I could 
never figure out *what* their intention was from the documentation. The 
paper has at least made their motivation clear, I still have to figure out 
how to actually use this feature now.

On Friday, March 23, 2018 at 6:33:27 PM UTC+1, Matthias Felleisen 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] Splitting up a GUI source file?

2018-03-23 Thread HiPhish
Hello Racketeers,

I am trying to create a GUI program, my problem is that the source code for 
the
GUI portion is growing out of control and I don't know how to split it up.

Here is some background info: the GUI is basically just a specialised 
frontend
to a database, the users clicks some stuff, the corresponding query is
constructed and sent off to SQLite using the db library.

The layout is to have one main window with a tab view. The application is
supposed to manage a small library, so each tab shows either the books, the
users, or the rentals. Here is a simple tree-view of the GUI:

  main window
  |
  |-- main tab view
  |
  |-- Books pane
  |   |
  |   |- List view of books (a table)
  |   |- Button to add a new book
  |   |- Button to remove a book
  |   |- Button to rent out a book
  |
  |-- Users pane
  |   |
  |   |- List view of users (a table)
  |   |- Button to add a new user
  |   |- Button to remove a user
  |
  |-- Rentals pane
  |
  |- List current rentals (a table)
  |- Button to remove a rental


I might reconsider the rentals part, but that's not relevant at the moment. 
My
problem is that even though the three panes don't need to know anything 
about
each other, they need to know about their parent (the main tab view), I 
cannot
split the code into a module hierarchy like the tree.

  (define main-window (new frame% [label "Library"]))
  (define main-tab-view (new tab-panel% [parent main-window]))

  (define books-panel (new vertical-panel% [parent main-tab-view]))
  (define books-table (new list-view% [parent books-pane]))
  (define books-buttons-pane (new horizontal-pane% [parent books-panel]))
  (define add-button (new button% [parent books-buttons-pane]))
  (define remove-button (new button% [parent books-buttons-pane]))
  (define rent-button (new button% [parent books-buttons-pane]))


And so on. This isn't much code, but add in all the callbacks and events, 
and
repeat that for all the three views, and the code quickly starts adding up.
How should I break it up into smaller modules?

-- 
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: The Racket School 2018: Create your own language

2018-03-19 Thread HiPhish
Will the content (video, PDFs, exercises and solutions) also be available 
online for those who cannot attend? The topic does sound very interesting, 
at the moment I only know how to use Racket like any other programming 
language, but I have no idea how to approach the language-oriented angle.

-- 
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: Getting young children started with Racket

2018-03-05 Thread HiPhish
I am not a father, so take everything with a grain of salt from me. Also,
obvious disclaimer, every child is different, you know your children best, 
and
all the usual stuff...

With that out of the way, I think computer illiteracy is one of the big
injustices that gets perpetrated in our modern society, people are being 
raised
to see computers as magic boxes and you are expected to be just a corporate
slave. Just look at the new Apple iPad commercial where the kid goes 
"what's a
computer?" and this is somehow supposed to be a good thing.

Every person should know the basics of how to use the command-line interface
and write simple programs. I view it like being mechanically competent: not
everyone needs to be a bike mechanic, but everyone should be able to at 
least
fix a flat tire or replace worn-out brakes. Imagine how pathetic and 
helpless
you would be if your bike had a flat tire and you had to bring it to a 
repair
shop and wait several days for something a person with basic training could 
get
done in a few minutes.

The same with computers. Being able to pipe together something in a shell or
throw together a quick script to get a job done frees people from being
dependent on corporations. Case in point, a while ago I was looking for a 
way
to split a PDF exactly in two, and after half an hour or so searching for a
program I was like "WTF am I doing with my life?" and gave up, so instead I
grabbed some Python PDF library, skimmed the documentation and within five
minutes I had a script that did exactly what I wanted.

With that said, I think first grade is a bit too young, but then again, 
every
child is different. You have to be careful to not make computers boring,
complicated or lame for her, or else you will put her off forever. I also
noticed that some people simply do not want to be tech-literate; I don't
understand it, but they are hostile to even the idea of learning the basics 
of
any craft. You will have to consider that possibility as well.

As for Racket, I'm not quite sure. I think the S-expression syntax,
immutability and functional programming are a bit harder to wrap your mind
around than the usual way of giving the computer a sequence of instructions 
to
follow. Maybe Python would be a better choice, it also has a much larger
selection of libraries. But it could also be because I originally came from 
the
imperative way of programming that I found the Lisp languages so weird.

I don't think being able to do math would be that interesting for a child. 
How
about instead you try making small arcade-like games together? Something 
like a
match-3 game or Snake (girls like cute games about eating stuff, PacMan was
specifically made to appeal to girls), a game that doesn't use scrolling and
not complicated collision detection. Or maybe some graphical programming
environment where you drag and drop commands instead of typing them. I don't
know what exists in that regard though, so I can't help you. I remember in
school we had a program where you had a little robot that would move tile by
tile, and you could program it in its own (very primitive) language. Here is
something similar to that:
https://www.swisseduc.ch/compscience/karatojava/javakara/

Now that I think about it, making something similar in Racket to be 
controlled with a language
that's not a bastardised Java would be a really cool project (not for a 
child
of course).

On Saturday, March 3, 2018 at 2:41:16 PM UTC+1, Paulo Matos wrote:
>
> Hello, 
>
> I have a 7yo daughter currently in 1st grade (Germany) and she was given 
> a password for the school computer. Having never touched a computer 
> before she is now being introduced to typing and the mouse. 
>
> I wonder if anyone has any experience with the following: 
>
> 1. Is it useful for a child this age to get introduced to programming if 
> they are not actively looking to learn? 
> 2. Is racket a good way to introduce it? 
> 3. Is 7yo / 1st grade a good time or too early and I should wait? 
>
> Of course, I can say, look... those math exercises you have? (16 - 2 = 
> _, 10 + 18 = _, etc) You can check your answers with a computer, you 
> have to type (- 16 2), (+ 10 18), etc. But is it useful or a waste of 
> mine and her time and there's a better way to begin? 
>
> Kind regards, 
> -- 
> Paulo Matos 
>

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

2018-02-16 Thread HiPhish
Thank you for the offer, but I am currently tied up myself a lot. I was just
looking into this because the topic had popped up here.

I should have provided some context as to how the Neovim Racket client 
works.
When I'm experimenting I use the regular REPL from my terminal, not the 
client,
that's why I mentioned the REPL. In a real remote plugin it works like this:
when Neovim calls a function that's defined by a remote plugin an API client
process is started, which can then receive responses, notifications and send
back responses (using the MessagePack RPC protocol).

Let's say I have a remote plugin like this:

  #lang racket
  (require nvim)

  (nvim-function "GetTwo" (λ (args) 2))

This defines a function called `GetTwo` that can be called from Neovim. 
Neovim
then sends a request to the Racket client, the client executes the function 
`(λ
(args) 2)` and sends the result (the integer `2` in this case) back to 
Neovim.

For a completion plugin Neovim would send the current portion of the word to
complete (and if necessary other information like the current file name) and
Racket would return a list of matching symbol names. The function defined on
the Neovim side is really just an interface wrapper for sending a message to
the client, all the heavy lifting can be done in Racket.


On Thursday, February 15, 2018 at 7:52:24 PM UTC+1, Greg Hendershott wrote:
>
> I guess I'm not clear who does what, e.g. do you start a REPL for the 
> user? 
>
> If so, the `current-namespace` that's in effect when you call 
> `read-eval-print-loop` should probably come from doing 
> `(dynamic-require mp #f)` then the result of `(module->namespace mp)` 
> (where `mp` is a module path).  That same namespace is the one you'd 
> want to give to `namespace-mapped-symbols` for a list of completion 
> candidates. 
>
> p.s. Feel free to look at racket-mode code for ideas. However that's 
> accumulated a lot of moving parts; so I'm not sure if it's a great 
> example as a starting point. 
>
> p.p.s. Also see xrepl. 
>
> p.p.p.s. Although I'm tied up now through next week, I'd be happy to 
> hop on IRC or Slack or 1:1 email sometime after Feb 25, and talk 
> through ideas if that would help? 
>

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

2018-02-15 Thread HiPhish
How would I get the module into Racket? My guess is that if the user is 
working
on a module that file would have to be required first to instantiate the 
module
before its file path can be sent over to `module->namespace`. At least 
that's
how I did it on the REPL. What if the file changes? Do I have to re-require 
it
somehow? I guess I'll have to read my way through the Language Model
documentation one day to understand enough of this.


On Thursday, February 15, 2018 at 2:17:32 AM UTC+1, Greg Hendershott wrote:

> `module->namespace` will give you a namespace "inside" a module. 
>
> The module can be the "top" module corresponding to a .rkt file using 
> `#lang`, or any nested submodule. 
>

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

2018-02-13 Thread HiPhish
Wow, this sounds like just the right thing. But the question is, how does 
one
get the namespace of the current text buffer? I guess I would need to 
somehow
send the buffer contents over to Racket and build a namespace out of that?

On Tuesday, February 13, 2018 at 1:39:49 PM UTC+1, William G Hatch wrote:
>
> 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-13 Thread HiPhish


On Monday, February 12, 2018 at 9:02:20 AM UTC+1, Gour wrote:
>
>
> I had tried tried several times with Emacs, but, for some strange reason, 
> very 
> soon I would experience some wrist pain and finally gave up on it. 
>
> Otoh, it does never occur when using Vim...yes, I also have Neovim 
> installed 
> and start using/learning it, but it is still light usage. 
>

For what it's worth, there is Evil Mode for Emacs. I have no idea how it
compares, as I said, I don't use Emacs, but maybe that's something for you.
Personally I try to use the home-row keys as much as possible, contorting my
wrist to reach ESC or the arrow keys, or stretching to reach the F-keys is
awful. My only problem is when the fingers on my left hand start hurting 
from
pressing Shift or CTRL (which I have mapped to Caps Lock) too often.

-- 
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 HiPhish
I'm afraid that's not possible. The functionality that gets the completion
candidates is written in Racket:

  #lang racket/base
 
  (require nvim/rplugin framework)
 
  (define (complete prefix)
(define completions (text:get-completions/manuals #f))
(filter (λ (x) (regexp-match (regexp-quote prefix) x)) completions))
 
  (nvim-function "RacketCompletions"
(λ (args)
  (complete (vector-ref args 0

Neovim has this feature called "remote plugins": a plugin can be written in 
any
language as long as there is an API client for it:
https://github.com/neovim/neovim/wiki/Related-projects#api-clients

I wrote the Racket client for cases like these where I can use a Racket 
library
to solve a problem in Neovim. In the future if someone implements proper
semantic auto-completion for DrRacket I will be able to take that 
functionality
and use it in Neovim as well.


On Friday, February 9, 2018 at 10:55:56 PM UTC+1, noch...@gmail.com wrote:
>
> Will your omni-completion also work in Vim?
>

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


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.


Re: [racket-users] Defining algebraic data types?

2018-02-06 Thread HiPhish
That makes perfect sense, thank you.

On Tuesday, February 6, 2018 at 12:43:07 AM UTC+1, Sam Tobin-Hochstadt 
wrote:

> The problem is that the definition of `(Dual-Number N)` includes `N`, 
> and therefore 
>
> (Dual-Number (Dual-Number String)) might either be a (D (D "x" "y") (D 
> "x" "y")) or just (D "x" "y"). Therefore checking D? can't tell that 
> you're in the `D` case because both cases could be a `D` case. 
>
> Sam 
>
>

-- 
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] Defining algebraic data types?

2018-02-05 Thread HiPhish
Why would that be a problem? The caller has to provide a function for 
"adding"
and "multiplying" an N, and as long as I define what it means to multiply 
and
add strings it shouldn't matter that I'm using a dual number where both
components are strings.

But I think this is a case of the rectangle-square problem: dual scalars 
and a
dual vectors a both a subset of dual quaternions that contain less 
information
than their supertype. I guess what I'm really looking for is a way to
"magically" promote objects.

A quaternion is an object of

  H = {a + bi + cj + dk | a,b,c,d ∈ R},

a vector is an object of

  V = {ai + bj + ck | a,b,c ∈ R},

but we can also view H as

  H = R × V = {(a, v) | a ∈ R, v ∈ V}.

The first definition of H is how it is usually defined and written out, but 
the
second definition makes it easier to compute the product:

  (p_r, p_v) (q_r, q_v) = (p_r q_r - p_v ⋅ q_v, p_r q_v + q_r p_v + p_v × 
q_v).

So far this is a simple hierarchy. But the set of scalars and the set of
vectors can be embedded in the set of quaternions:

  R → H, a ↦ (a, 0)  and V → H, v ↦ (0, v)

We can also define things like the "quaternion cross product" and 
"quaternion
dot product" for quaternions where the scalar part is zero:

  (0, p) × (0, q) := (p, p × q)
  (0, p) ⋅ (0, q) := (p ⋅ q, 0)

I'm starting to think this is becoming a pointless exercise. Maybe I should
just limit myself to "dual quaternions are a pair of quaternions" and
"quaternions are pairs of a scalar and a vector" and forget about the magic
subtyping.


On Tuesday, February 6, 2018 at 12:01:42 AM UTC+1, Sam Tobin-Hochstadt 
wrote:
>
> I'm not sure how the "If" got there. 
>
> But to say more, consider your function: 
>
>   (: dual-* (∀ (N) (→ (Dual-Number N) (Dual-Number N) (→ N N N) (→ N N 
> N) (Dual-Number N 
>   (define (dual-* d1 d2 * +) 
> (cond 
>   [(D? d1) 
>(D 
>  (D-real d1) 
>  (D-dual d1))] 
>   [else (D d1 d1)])) 
>
> Now you imagine instantiating `N` with things like `(Vector3 Real)`, 
> but if we instantiated it instead with `(Dual-Number String)`, then 
> you'd have a problem. 
>
> Sam 
>

-- 
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] Defining algebraic data types?

2018-02-05 Thread HiPhish
Did your email get cut off?

On Monday, February 5, 2018 at 6:00:05 PM UTC+1, Sam Tobin-Hochstadt wrote:
>
> This is an unfortunately common pitfall -- if you instantiated N with 
> something that includes a dual number, then the type error would be 
> pointing to a real bug. If 
>
> Sam
>

-- 
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] Defining algebraic data types?

2018-02-05 Thread HiPhish
Thank you for your answer, Sam.

1) does not really capture it, and 2) is a proof of concept that hasn't been
updated in almost a year. But it did give me a good idea: use Typed Racket 
and
have the type system work for me.

  (struct (N) D ([real : N] [dual : N]))
  (define-type (Dual-Number N) (U N (D N)))

Now a dual number is either an `N` (whatever an `N` is) or a pair of two 
`N`s.
My next idea was to implement dual number multiplication like this:

  (: dual-* (∀ (N) (→ (Dual-Number N) (Dual-Number N) (→ N N N) (→ N N N) 
(Dual-Number N
  (define (dual-* d1 d2 * +)
(cond
  [(and (D? d1) (D? d2))
   (D (* (D-real d1)
 (D-real d2))
  (+ (* (D-real d1)
(D-dual d2))
 (* (D-dual d1)
(D-real d2]
  [(D? d1) (D (* d2 (D-real d1)) (* d2 (D-dual d1)))]
  [(D? d2) (D (* d1 (D-real d2)) (* d1 (D-dual d2)))]
  [else (* d1 d2)]))

This captures the rule of multiplication of dual numbers in a generic way. 
For
a particular type of dual number one then has to provide the meaning of `+` 
and
`*` for the underlying `N`. So in case of dual vectors one could define

(define-type Dual-Vector (DualNumber (Vector3 Real)))
(: dual-vector-product (→ Dual-Vector Dual-Vector Dual-Vector))
(define (dual-vector-product dv1 dv2)
  (dual-* dv1 dv2 vector3-* vector3-+))

There is a problem with `dual-*` though: The predicate `D?` has type `(-> 
Any
Boolean : (D Any))`, and thus `D-real` and `D-dual` will return an object of
type `Any` rather than `N`, even though the type annotation for `dual-*` 
makes
it clear that the type would have to be `N`. Here is a simpler form of the
function (obviously wrong math, I just want to get the types right):

  (: dual-* (∀ (N) (→ (Dual-Number N) (Dual-Number N) (→ N N N) (→ N N N) 
(Dual-Number N
  (define (dual-* d1 d2 * +)
(cond
  [(D? d1)
   (D 
 (D-real d1) 
 (D-dual d1))]
  [else (D d1 d1)]))

When I try to enter the module I get the following error:

  > ,enter "source/types/dual-number.rkt"
  source/types/dual-number.rkt:30:5: Type Checker: Polymorphic function 
`D1' could not be applied to arguments:
  Argument 1:
Expected: N
Given:Any
  Argument 2:
Expected: N
Given:Any
  
  Result type: (D N)
  Expected result: (U (D N) N)
  
in: (D (D-real d1) (D-dual d1))


On Sunday, February 4, 2018 at 3:26:28 PM UTC+1, Sam Tobin-Hochstadt wrote:
>
> A few answers: 
>
> 1. Use struct subtyping to give a type that includes both kinds: 
> (struct dual ()) 
> (struct quaternion dual (scalar vector)) 
> (struct dual-quaternon dual (real dual)) 
>
> 2. Use a library that supports algebraic data types, such as 
> https://pkgs.racket-lang.org/package/datatype 
>
> Sam 
>

-- 
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] Defining algebraic data types?

2018-02-04 Thread HiPhish
Hell Racketeers,

I am trying to write an implementation of the mathematical concept of dual
quaternions in Racket. Dual quaternions are an algebraic type and there are
several equally valid way to look at them.

Let me give some background first. A dual number (a + bε) is similar to a
complex number (a + bi), except that the square of ε is 0 instead of -1. A
quaternion (a + bi + cj + dk) is like a complex number, except that it has
three complex units which all square to -1. A dual quaternion is either a 
dual
number where both components are quaternions, or a quaternion where all four
components are dual numbers. There are also "subtypes" of dual quaternoins: 
a
dual scalar is a dual quaternions where the vector parts of the two 
quaternions
are zero, and a dual vector (not to be confused with the dual vectors from
linear algebra) is a dual quaternions where the scalar part of both 
quaternions
is zero. Unlike the subtypes in OOP these algebraic subtypes have *less*
information than their parent (kind of like a square is a rectangle defined 
by
only one length instead of two). (If you want to get really down to it, dual
quaternions are elements of the Clifford algebra Cl^+(0, 3, 1).)

So my question is: what would be the best way of defining such algebraic 
types?
At first I wanted to create a struct:

(define vector (i j k))
(struct quaternion (scalar vector))
(struct dual-quaternon (real dual))

But this limits me to a "dual number where both components are quaternions"
view of the type. It also means that each dual scalar has be a sort of
mishapped dual quaternion.

-- 
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] How to integrate Racket with a .Net application?

2018-02-02 Thread HiPhish
For the people not following my bug tracker: I fixed it now.

On Friday, February 2, 2018 at 2:44:25 PM UTC+1, berthold.baeuml wrote:
>
> https://pkgs.racket-lang.org/package/msgpack is a nice package to use. 
> Thank you for providing it. But there is a bug for sequence lengths  >15 
> and <255. I filed an issue at 
> https://gitlab.com/HiPhish/MsgPack.rkt/issues/4
>
> Berthold
>

-- 
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] How to integrate Racket with a .Net application?

2018-02-01 Thread HiPhish
On Wednesday, January 31, 2018 at 4:17:09 PM UTC+1, Greg Hendershott wrote:
>
> Another way is for two (OS) processes to "pipe" I/O to each other. 
>

This is a great idea since it would allow to integrate any language with 
the .NET application. It is how Neovim does it: the main application is 
Neovim, which is written in C, and it acts as a server for a client 
application written in whatever other language. The protocol used is 
MessagePack RPC:
https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md

It is built on top of the MessagePack serialisation format. In a nutshell, 
MessagePack is like JSON, but binary. This makes it smaller to transport 
and faster to pack and unpack, but it loses the nice human-readability of 
JSON. I think that's a good tradeoff for data that is not meant to be 
stored and manipulated by a person, but instead passed around between 
processes.
https://msgpack.org/

I have already written a general-purpose MessagePack library for Racket, as 
well as a language client for Neovim:
https://pkgs.racket-lang.org/package/msgpack
https://pkgs.racket-lang.org/package/nvim-client

The MessagePack library is safe to use. The Neovim client is my first time 
doing something with RPC, so I'm not yet ready to call it stable. The part 
of the codebase which implements MessagePack RPC is not entangled with the 
Neovim-specific parts, so once the language client matures it will be easy 
to take it out and make it into a general-purpose MessagePack RPC library.

-- 
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: using vim to play with racket

2017-12-20 Thread HiPhish
> Maybe it is because of the fact that my daily job requires me to do manual
> compilation frequently but I don't find this very difficult.
Yeah, I use a package manager and only compile manually when I absolutely 
have
to because I don't like dealing with dependencies. A matter of perspective I
guess.


> In fact, opex works well with neovim as well for languages with providers
> (e.g. lua, python, ruby, shell and vim). I don't know much about remote
> plugins in neovim but I feel like they have a distinction between 
providers
> and remote plugins, because I can't seem to find some of the interfaces in
> vim (perl, tcl and mzscheme).
Right, providers and remote plugins are two different things. The idea 
behind
providers is that some functionality should not be implemented in Neovim, 
but
instead there should be a place to hook an application into. Take for 
example
the `:make` command: make is not built into Vim, instead you can set the
`makeprg` variable to a binary of you choice. Providers take this idea 
further,
offloading for example the clipboard support to an external program.

Remote plugins on the other hand are plugins written in a foreign language.
Where it might get confusing is that sometimes there is both: you can write 
a
plugin in Python as a remote plugin (new style) or you can write it in the 
old
style. When writing it the old style there needs to be a provider to supply 
a
Python implementation for the `:python` command to work (since there is none
built into Neovim itself).

There is no provider for the old `:mzscheme` command yet. I am planning to 
get
around to it, but it has very low priority. If anyone wants to help out I'm
open to that.

> If a remote plugin can provide such an interface with a similar command, 
then
> I think opex can simply be configured with something like the following:
>
>autocmd Filetype scheme let b:opex_cmd = 'RacketEval'

Right, that's the idea. Keep in mind that there is no difference between
functions defined in VimScript and those defined in remote plugins, so you
could also create a function reference like `funciton('RacketEval')`.

> I think the biggest problem is that the community more often talks about 
the
> possibilities rather than showing existing work. End users may simply 
prefer
> something that exists and simply works.
Many projects start with the idea of rewriting Vim, so you get someone who 
says
"I'm going to rewrite Vim in Python, and it will be much better code". Then 
he
starts implementing features one by one, and eventually he reaches the point
where he himself is satisfied with the result because it fits his own 
needs. He
never gets around implementing the rest and so you end up with a clone that
isn't compatible with anything from the Vim ecosystem. Neovim is a fork, so 
it
starts with full Vim compatibility and the developers can surgically remove 
and
replace the bits that need to be changed.

> In fact, I was already aware of neovim.rkt and I'm very glad you're here 
to
> give some feedback. It would be nice if you can give some information 
about
> the current situation in neovim and neovim.rkt.
Neovim.rkt is something I do on the side and it was my first time doing
something with asynchronicity and message passing, so progress is slow. It 
does
work though, but don't expect graceful error handling. I also haven't yet
committed to the public interface, but what I have now looks promising in my
opinion.

As for Neovim, that project is doing great. I have completely replaced Vim 
and
there are already plugins making use of its new features. Externalising
language support also makes it easier to maintain when you can just swap out
components. My personal killer feature is the terminal emulator. I thing the
fact that Vim has been copying features from Neovim instead of the other way
around should be telling enough.

-- 
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: using vim to play with racket

2017-12-20 Thread HiPhish
Having to re-compile Vim with support for a language is one of its bigger
drawbacks. It's fine for a common language like Python, but the more 
obscure it
gets, the less likely it is that your plugin will be of any use to other
people. You should take a look at Neovim:
https://neovim.io/

Neovim is a fork of Vim which aims to bring the code up to modern 
standards. It
is not a rewrite, so all existing plugins should work and the Neovim 
developers
keep up with new Vim patches.

One of the innovations in Neovim is its remote API. In Vim you have to 
compile
Vim with support for a foreign language, but in Neovim that support can be
retrofitted to the editor as an external process. So for example, if you 
want
to write Neovim plugins in Python you install the Python client via pip. 
And if
you want to write plugins in Racket you install my Racket client:
https://gitlab.com/HiPhish/neovim.rkt

You could then write an "evaluator" plugin in Racket like this:

#lang racket
;; Save in a file like '~/.config/nvim/rplugin/racket/eval.rkt'
(require nvim)
(nvim-function "RacketEval"
  (λ (args)
(define str (vector-ref args 0))
(call-with-input-string str (λ (in) (eval (read in))

This won't actually work with an argument like "(+ 2 3)", Racket complains 
that
the '+ is an undefined identifier, but that's a problem on the Racket side 
(I
don't know that much about Racket yet to be able to do eval magic), not on 
the
editor side. The RacketEval function is like any other Neovim function, 
except
that it offloads the work to an external process behind the scene, but the 
user
never notices that.

The Racket client is still under development, I have not yet committed 
fully to
the public interface and I need to take care of some edge cases when 
something
goes wrong. Other than that, the client fully works.


On Sunday, December 17, 2017 at 2:33:26 PM UTC+1, gokceh...@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.


Re: [racket-users] Re: Typed Racket has lowered my performance

2017-12-08 Thread HiPhish
No, I did the same thing, and only the first hundred tests work normally, 
the other 100 hand for several minutes. Maybe my computer is too weak, it's 
an early 2009 iMac with a 2.66GHz Core2Duo and 8GB of RAM. I also ran `raco 
setup msgpack` after making the change to the source file to make sure 
everything gets compiled properly.

On Monday, December 4, 2017 at 11:59:10 PM UTC+1, Sam Tobin-Hochstadt wrote:
>
> I'm not able to replicate that (see transcript below). Is there 
> something else I should be doing? 
>

-- 
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: Typed Racket has lowered my performance

2017-12-04 Thread HiPhish
When I change the return type of `unpack` to `Packable` instead of an 
explicit union of types the map packing test (`test/pack/map.rkt`) hangs.
https://gitlab.com/HiPhish/MsgPack.rkt/blob/master/unpack.rkt#L83
https://gitlab.com/HiPhish/MsgPack.rkt/blob/master/test/pack/map.rkt

-- 
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: Typed Racket has lowered my performance

2017-12-03 Thread HiPhish
Anything more I can do?
On Sunday, December 3, 2017 at 6:11:42 PM UTC+1, Sam Tobin-Hochstadt wrote:
>
> Thanks, that's very helpful. It's clear that the contract optimization is 
> working in the old code but not the new code, and we need to fix that.
>

-- 
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: Typed Racket has lowered my performance

2017-12-03 Thread HiPhish
Here is what happens when I run one of the array tests with the more
restrictive type specifications:

OK, passed 100 tests.
Running time is 70.75% contracts
75/106 ms

(-> (recursive-contract (or/c (and/c hash? (and/c hash-equal ... 75 ms
(lib msgpack/pack.rkt):24:9
pack 75 ms

After reverting the commit I get zero overhead:

OK, passed 100 tests.
Running time is 0% contracts
0/7 ms

The contract makes up 70% of the total runtime. I also looks like there is 
no
contract generated after reverting. Should I run the profiler on some other
tests as well?

On Sunday, December 3, 2017 at 3:33:10 PM UTC+1, Sam Tobin-Hochstadt wrote:
>
> Running the contract profiler [1] on your code would be quite helpful. 
>
> [1] https://docs.racket-lang.org/contract-profile/index.html 
>
> Sam 
>

-- 
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: Typed Racket has lowered my performance

2017-12-03 Thread HiPhish
Is there anything I can do to help investigate the issue? I have reverted 
my commit for the time being, and it's a difference like day and night.

On Sunday, December 3, 2017 at 12:36:16 AM UTC+1, Sam Tobin-Hochstadt wrote:
>
> I don't think the mutable/immutable issue should be as significant as it 
> seems here. Using the Any type shouldn't perform better the way you 
> describe, so we need to look more at what the actual contracts are doing.
>
> Sam
>

-- 
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: Typed Racket has lowered my performance

2017-12-02 Thread HiPhish
Now that I think about it, changing the types to be immutable is not really
correct either. There is no reason users should not be able to serialise a
mutable list, vector or hash table, just as they can serialise any mutable
scalar as well.

The result of unpacking bytes could be immutable, but would that make any
difference?

-- 
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 has lowered my performance

2017-12-02 Thread HiPhish
> The performance is probably because HashTable and Vector values can be
> mutable, so Typed Racket needs to do extra work to protect them.
> 
> To test this, I cloned msgpack, removed `Vector` from the `Packable`
> type, and changed `HashTable` to `Immutable-Hashtable`. Change here:
> 
https://gitlab.com/bennn1/MsgPack.rkt/commit/2a711200ad0efa1b974a3e5454f69d7004a74996
Thanks, I will change the hash tables to immutable, but I am going to keep 
the
vector as it is until immutable vectors land in Typed Racket. A slow
implementation is better than an incomplete implementation.

> When I run the tests in test/pack/map.rkt, I see:
> - 40 seconds with the types on master
> - 13 seconds with immutable types
> - 9 seconds on commit ac2b005 (before changing the types?)

Why is the version with immutable types still slower? Is it because it has 
to
recursively check the contents of the hash instead of just being satisfied 
with
anything? See, this is the thing that confuses me about Typed Racket, I 
thought
that making types more specific should improve performance or at least 
leave it
as it is because Racket does not have to check types at runtime unless
explicitly requested. Is it because the tests are written in untyped Racket 
and
specifying the Packable type generates a more expensive contract than the 
Any
type would?

> I'm working on a pull request to add Immutable-Vector to Typed Racket.
> That should be ready for the 6.12 release, and then msgpack can make
> the `Packable` type immutable.
> https://github.com/racket/typed-racket/pull/575
> 
> If that PR doesn't solve the performance problem, then I'd be happy to
> keep looking for something that does.
Racket 6.12 should come out around the end of January, right?


> It *should* be possible to make the predicate a proposition by
> changing the type of `packable?` to `(-> Any Boolean : Packable)`. But
> I couldn't get this to type check.
> Here's a simpler case that did work: http://pasterack.org/pastes/92542
>
> But it's probably easier to just use `(define-predicate packable? 
Packable)`
I think the problem is that Packable contains mutable types, which 
according to
the reference manual is not allowed:
https://docs.racket-lang.org/ts-reference/special-forms.html?q=make-predicate#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._make-predicate%29%29


> The type checker doesn't know that `v` is an integer. It just knows
> `v` is Packable. 
Right, that makes sense. Number and Packable intersect, but Packable is not 
a
subtype of Number.

-- 
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 has lowered my performance

2017-12-02 Thread HiPhish
Hello everyone,

A while ago I had written a MessagePack library Racket:
https://pkgs.racket-lang.org/package/msgpack

Yesterday I made a change to narrow down some of the types from `Any` 
(which is
wrong) to `Packable`. This has tanked my performance to the point where the
tests for non-scalar types (vectors and hashes) time out on the package 
server,
and thus fail.
https://gitlab.com/HiPhish/MsgPack.rkt/commit/0b6cdc7115389db97a8de2a5175c1feb4c939f8f

Please let me provide some context first: MessagePack is a serialisation 
format
similar to JSON, except binary, so it should be smaller and faster. Only
certain types can be packed (serialised) and unpacked (deserialised). Here 
is
the specification:
https://github.com/msgpack/msgpack/blob/master/spec.md

TL;DR: numbers, strings, byte string, booleans, some null element (I use 
void),
and arrays and dictionaries of any of these. I grouped the union of these 
types
into the compound type `Packable`:
https://gitlab.com/HiPhish/MsgPack.rkt/blob/master/packable.rkt#L24

I have also defined a predicate for this new type:
https://gitlab.com/HiPhish/MsgPack.rkt/blob/master/packable.rkt#L36

As you can see the `Packable` type is recursive; if an object is a vector 
or a
hash table then all its elements have to be packable as well. Could this be 
the
reason for the performance loss? Another thing I noticed is that the 
predicate
does not provide any proposition, if it succeeds the type checker is not
informed that the object is of type `Packable`. Another is that Typed Racket
seems unable to narrow down the type of the result. Take a look at this
example:

> (require msgpack)
> (define bs (call-with-output-bytes (λ (out) (pack 3 out
> bs
- : Bytes
#"\3"
> (define v (call-with-input-bytes bs (λ (in) (unpack in
> v
- : Packable
3
> (+ v 3)
; readline-input:8:3: Type Checker: type mismatch
;   expected: Number
;   given: Packable
;   in: v
; [,bt for context]
> (exact-integer? v)
- : Boolean
#t

So the type checker can figure out that v is an integer, but it cannot 
treat it
as one for addition.

-- 
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: Raising arbitrary errors in Typed Racket

2017-12-02 Thread HiPhish
Thank you everyone, I have gotten it up and running now. I'll make a formal 
announcement once I get an unrelated performance issue sorted out.

-- 
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] Raising arbitrary errors in Typed Racket

2017-12-02 Thread HiPhish
What is any-wrap/c? It does not show up in the documentation.

On Friday, December 1, 2017 at 9:17:18 PM UTC+1, Robby Findler wrote:
>
> Why not use any-wrap/c?
>

-- 
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] Raising arbitrary errors in Typed Racket

2017-12-01 Thread HiPhish
Thank you, I have made my own exception type now. Is `exn:fail:rpc` 
appropriate or should I use a different name? Using that name looks like 
I'm inserting it into Racket's own exception type hierarchy.

On Friday, December 1, 2017 at 8:11:27 PM UTC+1, Ben Greenman 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] Raising arbitrary errors in Typed Racket

2017-12-01 Thread HiPhish
Hello Racketeers,

I have been trying to port a module over to Typed Racket, and I have almost
succeeded except for one issue: raising an arbitrary object as an error.
Compare the following code:

;; Works fine
(raise 3)

;; Does not work
(raise (vector 1 2 3))

The error I get is
; nvim-client/client.rkt:244:55: Type Checker: No function domains 
matched in
;   function application:
; Domains: (U (Rec flat (U (Pairof flat flat) Boolean Char Complex 
Keyword Null
;   String Symbol)) exn) Any
;  (U (Rec flat (U (Pairof flat flat) Boolean Char Complex 
Keyword Null
;String Symbol)) exn)
; Arguments: (U (Immutable-HashTable Packable Packable) 
(Mutable-HashTable
;   Packable Packable) (Pairof Packable (Listof Packable)) 
(Weak-HashTable
;   Packable Packable) Boolean Bytes Ext Message-Args Null Real String)
;   in: (raise error)
; [,bt for context]

So I looked up the signature of `raise` and I get this:

> raise
- : (->* ((U (Rec
  flat
  (U (Pairof flat flat)
 Boolean
 Char
 Complex
 Keyword
 Null
 String
 Symbol))
 exn))
 (Any)
 (Nothing : (Bot | Bot)))
#

So what does this mean and what should I do? I am porting a module from my
Neovim client which uses the MessagePack-RPC protocol, and part of the 
protocol
is that any object that can be packed can be raised as an error.
https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md#error

Raising any object as an error would have allowed someone making an RPC 
request
to just do something like this:

(with-handlers ([packable? (λ (exn) (display exn))])
  (rpc-request "foo" '#(bar)))

What should I do instead? Create a new error type like `exn:fail:rpc`? Or 
am I
missing something here?

-- 
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: Alternatives to DrRacket

2017-11-26 Thread HiPhish
I use Neovim and I'm working on a Racket client for it:
https://gitlab.com/HiPhish/neovim.rkt

One of the cool features Neovim has over Vim is that it provides an API for 
remote processes; a client application can connect to the editor and they 
can communicate with each other. What that means in practice is that my 
Racket client allows you to write Neovim plugins in directly Racket. This 
would make it possible for example to re-use parts of DrRacket to write 
analogous Neovim plugins without having to re-invent the wheel. I don't 
know much about Emacs, but from looking at Racket Mode it looks like almost 
70% of it is Emacs Lisp. With a Racket client for Neovim the plugin could 
be written (almost?) entirely in Racket.

-- 
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] Neovim Racket host: control Neovim using Racket

2017-09-12 Thread hiphish
> These two problems are related AFAICT. Currently your package is set up
> as a multicollection package but the info.rkt file is only in the top-level
> directory, whereas it should go in the subdirectories. I suspect you don't
> actually want a multicollection package in this case.
Yes, you're right, I only want one collection in the package. Or rather one
collection and a bunch of other files.
 
> What you may actually want to do is put the info.rkt file in only the "nvim"
> directory and then change the package URL on the package server to point only
> to the subdirectory.
Won't this mean that raco then only installs the sub-directory? The
issue is that there are two components needed: the API client (a Racket
library) and the Racket host (a Neovim plugin). The Right Way(TM) is to
have one repository that doubles as both.

I guess what I could do is tell people to install the repo as a Neovim
plugin first, and then as a Racket package second, thus having two
copies of the repo on the website. That's what the Common Lisp client
does:
https://github.com/adolenc/cl-neovim/#installation
Since in Quicklisp everything is explicit there is no danger that the
Vim plugin directories will get mistaken for Common Lisp libraries.

> This seems like a very cool project! As a long-time vanilla vim user, I'll 
> have
> to try neovim and the bindings out.
I found out about Neovim by chance when I was looking for a way to have
a terminal running inside Vim, all I got was barely working hacks and
then out of nowhere this thing popped up. I haven't looked back at Vim
since then. And I was really considering switching to Emacs with Evil
Mode because of Vim's lack of non-blocking plugins.

-- 
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] Neovim Racket host: control Neovim using Racket

2017-09-11 Thread hiphish
Hello Racketeers,

I wrote a new package, an API client for the Neovim text editor:
https://gitlab.com/HiPhish/neovim.rkt
https://pkgs.racket-lang.org/package/nvim-client

With this it is possible to control Neovim with Racket. In particular,
it is now possible to write Neovim plugins in Racket rather than
VimScript.


What is Neovim?
===

Neovim (or Nvim for short) is a fork of Vim. Unlike the usual "I'll
rewrite Vim in my favourite language" projects which aim to imitate Vim,
but end up being incompatible with most Vim plugins, Neovim intends to
clean up the plumbing, but keep the porcelain the same. This means we
get to keep using the existing ecosystem of extensions and other
techniques, while the core of the editor gets cleaned up and new
features get added.

One such new feature are the language hosts. In Vim if you want to write
plugins in a foreign language you have to compile Vim with support for
that language. For something as common as Python you can be fairly
certain that most users have it and that support in Vim is always up to
date. However, the more you move away from that, the worse it gets. Vim
has support for Racket, but it's still called MzScheme and who knows
when it was last updated.


What is the Racket host?


Neovim externalises the problem. The editor no longer comes with support
for any foreign languages, only VimScript and Lua are the default.
Instead, it defines an API interface so that external programs can
connect to the editor and exchange messages. Among other things this
allows plugins to be written in any language if a host for that language
exists. The maintenance burden is now on the host author and hosts can
be added, removed and swapped without having to re-compile Neovim.
Messages can be sent asynchronously, so it is possible for example to
have semantic code highlighting without blocking:
https://github.com/arakashic/chromatica.nvim/

This type of communication works both ways: Neovim can control a Racket
instance, but Racket can also control a Neovim instance. One could write
a GUI for Neovim in Racket, the GUI would be just a Racket program which
spawns a headless Neovim instance, connects to it, and then sends user
inputer over and receives the result for display.

What I am personally interested in are remote plugins, plugins written
for Neovim in Racket. See the readme of the repo to see what a remote
plugin looks like. I would like to make use of the DrRacket code to
implement IDE-like capabilities as a plugin.


Status of the Racket host
=

Right now the host is feature-complete, so if anyone wants to try it out
it is ready. There are a few issues I would like to see sorted out
before it can considered to be finished.

- Why is the documentation not building? I can compile the scribble file
  normally, but running `raco setup` does not build it, and it doesn't
  show up on https://docs.racket-lang.org/ either.

- The directory layout is weird. The reason for this is that the repo is
  both a Racket package, and a Neovim plugin and has to be installed as
  both. This works fine, but now Racket seems to think that there is
  also an "autoload", "doc", "plugin" and "test" collection. Is there a
  way to tell Racket "only the nvim directory is a collection"?

- The API bindings (nvim/api.rkt) are a big sore in my eyes. Neovim
  defines a set of "API methods", basically the specifications for
  messages you can send over RPC.
  https://neovim.io/doc/user/api.html#api-global
  
  Right now I'm generating the function bindings using macros, but it
  looks weird:

;; Set the current line
(set-current-line "Hello world!")
(define two (eval "2"))  ; This is not the Racket eval

  There is no exclamation mark and the API can collide with existing
  names. The name collision can be resolved by adding a prefix like
  `nvim-` or `nvim:`. Which one would be better?

  Would it be better to have separate getter- and setter functions, or
  is it better to use `set!`?

;; Setters and getters
(define line (get-current-line))
(set-current-line! (string-append line "!!!"))
;; using set!
(define line (current-line))
(set! (current-line) (string-append line "!!!"))

  At the moment I am generating the API automatically, but I think I'll
  have to do it manually. I can for example append a `!` if the word
  `set_` occurs in the name, but there are also other functions which
  have side effects (e.g. `nvim_del_current_line()`). And some like
  `nvim_call_function()` may or may not mutate state.

  Some API calls are limited to a part of the editor, like a tab page, a
  window or a buffer. What should their names be?

;; Two prefixes
(define line-count (nvim-buffer-line-count buf))
;; One prefix
(define line-count (buffer-line-count buf))
;; Keyword argument
   

Re: [racket-users] Need help improving a macro

2017-08-30 Thread hiphish
> I would love to see some library provide better abstractions for
> fairly common cases of keywords like this
Honestly, I don't think I need a library, I need better knowledge. Your
macro works, but I have no idea how I could have come up with it. The
Racket guide gives a good introduction to the language, but when it
comes to the macro system which is basically a language on its own, all
I get is one chapter in the the guide and a huge reference manual. How
did other people learn Racket meta programming? Read the implementation?
I feel like I have opened a box full of electronics parts and all parts
are labeled and documented perfectly, but I have no idea what any of
those labels mean.

It looks like your macro is turning strings into symbols. I changed

  (define-syntax (register-nvim-function! stx)
(displayln stx)
#`(begin))

into

  (define-syntax (register-nvim-function! stx)
(displayln (syntax->datum stx))
#`(begin))

so that it would print the list-representation of what it got, and all
the strings are symbols:

  > (define-nvim-function (foo bar baz) #:name "_foo" #:eval (void) #:sync 
"hello"
  (display bar)
  (display baz))
  (register-nvim-function! foo _foo #:eval (void) #:sync hello)

This is not much of an issue since symbols are packed into strings, but
it is a weak spot.

> You would probably then want to add contracts using `expr/c`.
Yes, once I can wrap my head around how the macro works I can harden it.

> I also wonder if you really want to have a mandatory "name" argument
> or if you should infer it based on the identifier being defined
> (perhaps with an option to override). 
I was considering that, but the Racket conventions for function names
(lower-case, using hyphens) are not valid Neovim function names. The
user would either have to use un-Racketey names in Racket code or
specify the name any time, so I might as well make the name mandatory.


> here is how I might write this:

Let me see if I understand how your macro works.

  (define-splicing-syntax-class options
  #:attributes (name [opt 1])
  (pattern (~seq (~alt (~once (~seq #:name   name:expr))
   (~optional (~seq #:range range:expr))
   (~optional (~seq #:eval   eval:expr))
   (~optional (~seq #:sync  sync?:expr)))
 ...)
   #:with (opt ...)
   #`(#,@(for*/list ([clause (in-list (list (attr? #:range range)
(attr? #:eval   eval)
(attr? #:sync  sync?)))]
 #:when clause
 [term (in-list clause)])
   term

This is the syntax class of all the keyword-value pairs. My first
mistake was using `~alt`, I should have used `(~seq (~alt ...))` instead
because I accept a sequence of pairs, not just one pair. The syntax
class also matches all the pair at once instead of each class instance
matching only one pair.

The `#:with` directive mathes the `opt ...` pattern against a syntax
object which has been constructed out of all the non-name pairs. But how
does the `name` attribute get its value? Because it's not an `opt`?


  (syntax-parse stx
[(_ raw-lhs:expr opts:options
body:expr ...+)

The `raw-lhs` is the thing we want defined. How does it know to match
both `foo` and `(foo bar baz)`?

  #:do [(define-values (ident-stx rhs-stx)
  (normalize-definition #'(define raw-lhs body ...) #'λ #t #t))]

I don't understand why we need this. It takes apart a definition we
built on the fly, takes it apart, but in the template we put thing back
together in the same order:

  #'(begin 
  (define ident rhs)
  (register-function! ident opts.name opts.opt ...))]))

-- 
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] Need help improving a macro

2017-08-29 Thread hiphish
Hello,

I have a working macro written using `syntax-parse`, but it still has
some kinks that need to be worked out. What I want the macro to do is
define a function and as it as input to another function. Example:

  (define-nvim-function (foo bar baz) #:name "foo" #:sync #f
(display bar)
(display baz))

This would expand to

  (define (foo bar baz)
(display bar)
(display baz))
  (register-nvim-function! foo "foo" #:sync #f)

The `register-nvim-function!` function is defined like this:

  (define (register-nvim-function! proc name
   #:range [range #f]
   #:eval  [eval  (void)]
   #:sync  [sync? #f])
...)

The point is that `proc` and `name` are mandatory, but the keyword
arguments are optional. I want the keyword arguments of the macro to be
optional as well, except for the name, and their order should not
matter. Here is what I got so far:


  (define-syntax (define-nvim-function stx)
(syntax-parse stx
  [(define-function (head:id arg-id:id ...)
(~alt (~once (~seq #:name name:expr)
 #:name "#:name name")
  (~optional (~seq #:range range:expr)
 #:name "#:range range"
 #:defaults ([range #'#f]))
  (~optional (~seq #:eval eval:expr)
 #:name "#:eval eval"
 #:defaults ([eval #'(void)]))
  (~optional (~seq #:sync sync?:expr)
 #:name "#:sync sync?"
 #:defaults ([sync? #'#f])))
...
 body:expr ...+)
   #'(define-function head #:name name #:range range #:eval eval #:sync 
sync?
   (λ (arg-id ...) body ...)) ]
  [(define-function head:id
(~alt (~once (~seq #:name name:expr)
 #:name "#:name name")
  (~optional (~seq #:range range:expr)
 #:name "#:range range"
 #:defaults ([range #'#f]))
  (~optional (~seq #:eval eval:expr)
 #:name "#:eval eval"
 #:defaults ([eval #'(void)]))
  (~optional (~seq #:sync sync?:expr)
 #:name "#:sync sync?"
 #:defaults ([sync? #'#f])))
...
 body:expr)
   #'(begin
   (define head body)
   (register-function! head name #:range range #:eval eval #:sync 
sync?))]))

The macros supports two variants, similar to how `define` allows two
ways of defining a function. The problems with this implementation are:

- The giant blob of keyword arguments is repeated twice
- The template is listing all the keyword arguments the function can
  take

I was thinking of a macro more like this:

  (define-syntax (define-nvim-function stx)
(define-splicing-syntax-class option
  (pattern (#:namename:expr))
  (pattern (#:range range?:expr))
  (pattern (#:eval   eval?:expr))
  (pattern (#:sync   sync?:expr)))
(syntax-parse stx
  [(define-function (head:id arg-id:id ...) option:option ...
 body:expr ...+)
   #'(define-function head option ...
   (λ (arg-id ...) body ...)) ]
  [(define-function head:id option.option ...
 body:expr)
   #'(begin
   (define head body)
   (register-function! head option))]))

This won't work though. First I lose the optional/unique specifications
from above, second the keyword-value pairs are wrapped in parentheses
for some reason. Expansion becomes

  (register-function! foo (#:name "foo") (#:sync #f))
  ;; instead of
  (register-function! foo #:name "foo" #:sync #f)

What am I doing wrong here? I have a pretty solid grasp of Racket thanks
to the great guide, but when it comes to macros I am still totally lost.

-- 
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] Generate function defintions at compile time

2017-08-23 Thread hiphish
Thank you all for your answers, I think I got it right this time, but I
would still appreciate feedback:
https://gitlab.com/HiPhish/neovim.rkt/blob/master/nvim/api.rkt

I think what was confusing me was that I was thinking of Racket macros
like Common Lisp macros. Instead of trying to build a list that will be
the resulting S-expression I needed to build syntax objects.

> Neil Van Dyke wrote
> If you define a kind of domain-specific language (DSL) syntax
> extension in Racket for your Neovim API, your specification might then
> look like this (with the "..." filled in): 
Wouldn't making a DSL be overkill? Also, I don't have a choice in the
matter how the API data is stored, a hash table is what I receive. I do
not get the decide what the API is myself.

> BTW, consider making the `require` name be simply `neovim` or `nvim`,
> not `neovim/api` or `nvim/api`.  Or call the package `neovim-api`. 
The API is only a part of the library, there is also the "client"
(connecting to a Neovim instance) and the Racket "host" (allowing Neovim
plugins in Racket). I might later re-export the bindings from `nvim/api`
through `nvim`, I haven't decided on that yet.

> Also BTW, consider including the string "neovim" or "nvim" in the
> names of all provided identifiers of your API package, such as
> `neovim-command` instead of `command`.
Isn't this the sort of thing that should be handled by `prefix-in`? The
Common Lisp client prefixes `nvim:`
https://github.com/adolenc/cl-neovim/#neovims-api
https://github.com/adolenc/cl-neovim/blob/master/src/package.lisp#L26



> Philip McGrath wrote
> I guess my first question would be where does the hash table in
> nvim/api/specification.rkt come from, where else is it used, and is it
> necessary for the format to be what it currently is.
The hash table comes from Neovim. I can either send an RPC request (using
this library) or run `nvim --api-info` and read from Neovim's standard
output. The result is in the MessagePack format; MessagePack is similar
to JSON, except it's binary instead of text-based.
http://msgpack.org/

I wrote my own MessagePack library, and since the MessagePack standard
does not promise that keys of dictionaries need to be strings, only an
"object" I decided to unpack keys the way they are. I also use vectors
when unpacking MessagePack arrays because vectors are closer to what
arrays are than a linked list.



> Ryan Culpepper wrote
> IIUC, you are doing argument/result checking and conversion at run
> time.
No, I want to do everything at compile time. Your second code example is
what helped me to get it working, although I still don't quite
understand what `syntax-local-introduce` does and what the `#'here`
syntax object is supposed to be (I guess just some arbitrary syntax
object that's define right "here").

I'm not concerned with runtime type checks for now, I'll eventually port
the library to Typed Racket, then I'll just add the type annotations
above the function definition.

-- 
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] Generate function defintions at compile time

2017-08-22 Thread hiphish
Hello,

I am writing a Racket library which will make it possible to control the
Neovim text editor using Racket. People will be able to use Racket to
control Neovim, as well as write plugins for Neovim in Racket.
https://gitlab.com/HiPhish/neovim.rkt

So far it looks good, but I am stuck on macros. There is a hash table
which serves as a specification for which functions to generate, it is
stored in the file 'nvim/api/specification.rkt'. This table has the key
"functions" which contains a vector of more hash tables.

I need this information to generate function definitions for users to be
able to call Neovim procedures from Racket. So instead of writing
something like

  (api-call "nvim_command" '#("echo 'hello world'"))

users should be able to write

  (require nvim/api)
  (command "echo 'hello world'")

For this I need to loop over the functions vector like this:

  (define functions (hash-ref api-info "functions"))
  (for ([function (in-vector functions)])
(define name   (hash-ref function   "name"))
(defien params (hash-ref function "parameters"))
`(define (,(string->symbol name) ,@params)
   (api-call ,name (vector ,@params

Reality is a bit more complicated because the parameters are not a list
but a vector of vectors, but that's besides the point. The question is:
how do I do this? A regular for-loop at runtime will not work, and
wrapping this in begin-for-syntax doesn't produce actual module-level
definitions.

I tried doing it with a macro:

  (define-syntax (api->func-def stx)
(syntax-case stx ()
  [(_ api-name api-params)
   (with-syntax ([name
   (datum->syntax stx
 (string->symbol
   (function-name (eval (syntax->datum #'api-name)]
 [arg-list
   (datum->syntax stx
 (vector->list
   (vector-map string->symbol (eval (syntax->datum 
#'api-params)])
 #`(define (name #,@#'arg-list)
 (api-call api-name (vector #,@#'arg-list]))

This *seems* to generate the proper definition, although I'm not really
sure. But how can I write the loop now so that it covers all function
definitions? I don't need to re-use the macro, I only need it once, so
if there was an easier solution like my for-loop above that does it in
place it would be even better.

-- 
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] Requiring module beneath top level?

2017-08-22 Thread hiphish
> On Fri, Aug 18, 2017 at 7:08 PM,   wrote:
> I think you want `dynamic-require`:
> [http://docs.racket-lang.org/reference/Module_Names_and_Loading.html?q=dynamic-require#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29]
Thank you, that's what I needed. I'll limit myself to just requiring single 
files for the time being.

-- 
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] Requiring module beneath top level?

2017-08-18 Thread hiphish
Hello Racketeers,

A while ago I announced my MessagePack library here and I mentioned that
I was needing it for a client library for the Neovim text editor. Since
then I have been writing this client library and now I'm at a point
where I need help.

Let me first give you some context: Neovim is a fork of Vim which allows
people to write remote plugins in any language. Remote plugins are run
by a separate process which is a client to the Neovim server. Basically
this means I can write Neovim plugin in Racket (given a Racket host) and
call functions written in Racket from Neovim and use them in Neovim
plugins.

For this to work the functions defined in Racket need to tell Neovim
about themselves, they need to register their specifications. Here is
how the process works: Neovim first searches for paths to remote
plugins, in this case the pattern is "rplugin/racket/*" where "rplugin"
is a directory of a Neovim plugin. This means there are many such paths
that all end in "/rplugin/racket/*". Neovim then passes the list of all
these paths on to the Racket client.

The client then has to load or require all these plugins so that they
can register their specifications. I'll try to capture the sequence of
events in a list:

1) Neovim launches
2) It collects a list of all Racket remote plugins, where a remote
   plugin is either a file ending in ".rkt" or a directory
3) Neovim launches a Racket instance as the client
4) Neovim sends a request to Racket with a list of all the plugin paths
5) Racket has to set up the specifications
6) After Racket responds back Neovim asks for the specifications
7) Racket sends back a hash table containing the specifications

Step 5 is the one that is giving me trouble. Here is how the Racket
client is launched:

  racket -eee '(require (file "autoload/host/bootstrap.rkt"))' \
  '(require neovim)' \
  '(start-host)'

The first instructions requires a bootstrapping module which will get
the host ready to receive the requests in step 4 - 7. It works, I have
tested it. In the bootstrapping module I also want to process the
plugins. A remote plugin has to be required so that its side effects are
performed. A declaration in a remote plugin could look something like
this:

  (require neovim/rpc)

  (define (two) 2)
  (register-function! two #:name "Two" #:sync #t)

Ideally both would be wrapped up in a macro, this is just an idea. The
point is that the Racket function foo is not supposed to leave the
module, but the side effect of registering it in a global table must
happen.

Here is an idea of what a plugin registration function could look like:

  (define (load-plugins paths)
;; Process one plugin at a time
(define (load-plugin path)
  ;; Add the path (or its stem) to the search paths
  ;; Require the plugin (the plugin should register itself)
  )
(vector-map load-plugin paths)
"Loaded plugins")

The sequence of paths was received from Nvim as a vector, and I map over
every path, requiring the module/collection. The problem is that I
cannot use (require (file path)) because the require is not a top- or
module level. The question is: what can I do instead? I would like all
the side effects that usually go with "require", but since the
registration happens via RPC request it cannot be at module level. I can
also pass arbitrary arguments to the racket binary, so I don't need to
do all the work in Racket.

I hope this explanation makes it clear what I'm trying to achieve. Of
course if there is a better way of adding a bunch of collections and
modules I am open to that as well.

-- 
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: Racket from Homebrew has trouble when upgrading

2017-08-07 Thread hiphish
It seems I got it working now. I deleted `(find-system-path 'config-dir)` and 
`(find-system-path 'addon-dir)`. My bet is that the former was the culprit. 
We'll see about that when 6.11 is released.

-- 
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] Racket from Homebrew has trouble when upgrading

2017-08-07 Thread hiphish
Hello,

I have had this same problem when I was upgrading Racket from 6.8 to 6.9, and 
now again when upgrading from 6.9 to 6.10. Basically what happens is that raco 
downloads and installs all packages as if they were for the previous version of 
Racket.

I installed Racket as 'brew install minimal-racket' and it installed Racket 
under `/usr/local/Cellar/minimal-racket/6.10/` as expected. Next, I ran `raco 
pkg install --auto drracket` and what happened was that raco downloaded the 
packages for the 6.9 release and installed them under 
`/usr/local/Cellar/minimal-racket/6.9/`. I checked and that directory indeed 
did not exist prior to running raco.

This messes up things because now Racket and raco get confused. At first 
everything runs normally, but after running `raco setup` (to update a package I 
have been developing locally) the symlink to the `raco` binary is gone from 
`/usr/local/bin`. The binary is still there in the `6.10/bin` directory though. 
There is probably even more things messed up, but raco was the first one I 
noticed.

I had the same problem when I was upgrading from 6.8 to 6.9 and I don't know 
what made it go away. Is this a Racket problem or a Homebrew problem? My bet is 
on Racket since the initial installation seems to be proper, but maybe Homebrew 
compiled Racket with the wrong options?

Any ideas what could be going on here? I know that there is a cask, but I 
prefer to install software the Unix way. Thanks in advance.

-- 
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: Need help porting a library to Typed Racket

2017-08-07 Thread hiphish
Thank you for your response. Right now I cannot implement it because either 
Racket or my package manager (or both) keeps breaking itself, but I will keep 
in mind what you said.

-- 
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: Need help porting a library to Typed Racket

2017-08-06 Thread hiphish
*bump* I hope bumping is not frowned upon here. I just need to sort this one 
last issue out 

-- 
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: [ANN] MessagePack implementation for Racke

2017-07-26 Thread HiPhish
On Tuesday, July 25, 2017 at 11:37:48 PM UTC+2, Lehi Toskin wrote:
> One thing I'm curious about is what things can you and can you not pack? In 
> the README it shows bytes being packed, which seems a little obvious, but 
> what about (transparent) structs? Hashes? Lists? I'm very interested in this 
> package... for science!

In theory anything can be packed as long as you can agree on *how* it should be 
packed. For example, if you have a point '(struct point (x y))', how should 
that be packed? There is no "point" type in MessagePack and no direct 
correspondance, so you would have to tell the recipient of your data "a point 
looks like this: ...". You could use the MessagePack 'ext' type, it consist of 
an 8-bit integer as a type tag and raw binary data, so you could agree with the 
recipient that the tag '13' stands for point and the data is two big-endian 
64-bit numbers in the order 'x' and 'y'. Or you could pack a transparent struct 
as a string that you can 'read' and 'write' in Racket.

For hash tables there is the map type and for vectors and lists there is the 
array type, so those are direct 1:1 correspondences. The elements of these are 
themselves individually packed, so if you have a list of hash tables that 
structure will be preserved.

I think adding the ability to define your own packing functions as additions to 
the library is something that's worth looking into later. Then you could define 
your own 'pack-point' and add it to the generic 'pack' function.

-- 
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] Struct declaration conflict if a file is required implicitly

2017-07-23 Thread hiphish
On Sunday, July 23, 2017 at 5:43:51 PM UTC+2, Ryan Culpepper wrote:
> On 07/23/2017 07:26 AM, Alejandro Sanchez wrote:
> > Hello everyone,
> > 
> > I am working on this project: https://gitlab.com/HiPhish/MsgPack.rkt/
> > 
> > I am writing test cases and I ran into a problem with my ‘ext’ structure. 
> > It is declared in the file ‘msgpack/main.rkt’, which is required in the 
> > file ‘msgpack/pack.rkt’ (also in ‘msgpack/unpack.rkt’). For my test case 
> > the test file looks like this:
> 
> It looks like msgpack/pack.rkt requires "../main.rkt" rather than 
> "main.rkt". There isn't a "../main.rkt" checked in, so maybe you have a 
> stale file getting loaded? (It could be at "../main.rkt" or possibly 
> "../compiled/main_rkt.zo".)
> 
> Ryan

Thank you so much! I feel so stupid now, that file path is a leftover from when 
the directory structure was different. Now it works perfectly.

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