Re: [racket-users] Reliably propagating received log messages to ports

2018-01-31 Thread George Neuner



On 1/31/2018 5:00 PM, Alexander McLin wrote:
During the tool's start up period prior to calling the main function I 
set up a log receiver to receive messages at the desired level and 
place it inside a sync loop within its own thread. Each time a sync 
event is received, it is written out to the port, then loop back to 
waiting for the next sync event.


It works reasonably well except I have a new problem, when the tool 
exits, it often exits before the thread handling the log receiver 
propagation to the port has finished receiving all the log events, as 
a result my logging output is frequently truncated.


Given this undesired situation, I need to figure out a better way to 
reliably propagate all log messages to ports before the tool exits 
normally or due to a raised exception.


There may be a better way, but I handle this kind of thing with 
dynamic-wind.  The program's main function looks like


(start
    :
(dynamic-wind
        (lambda ()
            ;;; startup services
            ... )

        (lambda ()
            ;;; program's purpose
            ... )

        (lambda ()
            ;;;shutdown services
         ...  )
        )
    :
    )

There is `with-logging-to-port` except I will need to set up multiple 
ports and the idea of wrapping the tool's main body with multiple 
`with-logging-to-port` for each port isn't appealing and it still 
doesn't resolve the problem.


I use  with-logging-to-port  in the individual logger threads to direct 
their output.  I don't wrap it around all the code.



I was wondering if anyone has a better suggestion? Is there a way to 
detect if there are pending log events waiting to be received by the 
log receiver?


Not that I know of, but if you structure the logger so that it must be 
specifically shut down, you can drain the message queue before terminating.



George

--
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] Datalog Question

2018-01-31 Thread Jay McCarthy
Something like

kevin(Y) :- foo(x, Y), Y != 3.
kevin(Y)?





On Wed, Jan 31, 2018 at 5:13 PM, Kevin Forchione  wrote:
> Can anyone tell me how I would use the datalog = and != tokens? The 
> documentation says they can separate terms, such as  != . In the 
> program below, how would I create a query for foo(x, ?) where ? is not 3?
>
> #lang datalog
>
> foo(bil, 1).
> foo(bob, 3).
> foo(joe, 2).
>
> I imagine I’d have to create a rule of some sort.
>
> -Kevin
>
> --
> 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.



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
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] Datalog Question

2018-01-31 Thread Kevin Forchione
Can anyone tell me how I would use the datalog = and != tokens? The 
documentation says they can separate terms, such as  != . In the 
program below, how would I create a query for foo(x, ?) where ? is not 3?

#lang datalog

foo(bil, 1).
foo(bob, 3).
foo(joe, 2).

I imagine I’d have to create a rule of some sort. 

-Kevin

-- 
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] Reliably propagating received log messages to ports

2018-01-31 Thread Robby Findler
I think the right approach here is to recognize that you have a more
complex protocol than is currently reflected in your code and dive
into Racket's evt support.

In this particular case, I suggest you make a new channel that the
loop in the thread also listens on, If yet another channel comes in on
that one, you flush all pending messages and then send a message back
saying "I'm done". Then the code that catches the exit can use that
mechanism to communicate "I'm about to exit, please finish up".

Robby


On Wed, Jan 31, 2018 at 4:00 PM, Alexander McLin  wrote:
> So I am using Racket's logging facilities in a command-line tool I'm
> developing. I have various defined loggers in a sensible hierarchical
> configuration for use as needed.
>
> During the tool's start up period prior to calling the main function I set
> up a log receiver to receive messages at the desired level and place it
> inside a sync loop within its own thread. Each time a sync event is
> received, it is written out to the port, then loop back to waiting for the
> next sync event.
>
> It works reasonably well except I have a new problem, when the tool exits,
> it often exits before the thread handling the log receiver propagation to
> the port has finished receiving all the log events, as a result my logging
> output is frequently truncated.
>
> Given this undesired situation, I need to figure out a better way to
> reliably propagate all log messages to ports before the tool exits normally
> or due to a raised exception.
>
> There is `with-logging-to-port` except I will need to set up multiple ports
> and the idea of wrapping the tool's main body with multiple
> `with-logging-to-port` for each port isn't appealing and it still doesn't
> resolve the problem.
>
> I was wondering if anyone has a better suggestion? Is there a way to detect
> if there are pending log events waiting to be received by the log receiver?
>
> I realize the fundamental nature of my issue is that Racket's logging is
> asynchronous while I want synchronous behavior. I may be better off just
> using old-fashioned `println`s
>
> Thank you for your suggestions.
>
> Alexander McLin
>
> --
> 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.

-- 
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] Reliably propagating received log messages to ports

2018-01-31 Thread Vincent St-Amour
Does `with-intercepted-logging` do what you want?

It should take care of the sychronization aspects, like `with-logging-to-port`
does, while letting you do whatever you want with the message, e.g., sending
them to different ports.

Vincent



On Wed, 31 Jan 2018 16:00:58 -0600,
Alexander McLin wrote:
> 
> So I am using Racket's logging facilities in a command-line tool I'm 
> developing. I have various defined loggers in a sensible hierarchical 
> configuration for use as needed.
> 
> During the tool's start up period prior to calling the main function I set up 
> a log receiver to receive messages at the desired level and place it inside a 
> sync loop within its own thread. Each time a sync event is received, it is 
> written out to the port, then
> loop back to waiting for the next sync event.
> 
> It works reasonably well except I have a new problem, when the tool exits, it 
> often exits before the thread handling the log receiver propagation to the 
> port has finished receiving all the log events, as a result my logging output 
> is frequently truncated.
> 
> Given this undesired situation, I need to figure out a better way to reliably 
> propagate all log messages to ports before the tool exits normally or due to 
> a raised exception.
> 
> There is `with-logging-to-port` except I will need to set up multiple ports 
> and the idea of wrapping the tool's main body with multiple 
> `with-logging-to-port` for each port isn't appealing and it still doesn't 
> resolve the problem.
> 
> I was wondering if anyone has a better suggestion? Is there a way to detect 
> if there are pending log events waiting to be received by the log receiver?
> 
> I realize the fundamental nature of my issue is that Racket's logging is 
> asynchronous while I want synchronous behavior. I may be better off just 
> using old-fashioned `println`s
> 
> Thank you for your suggestions.
> 
> Alexander McLin
> 
> -- 
> 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.

-- 
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] Reliably propagating received log messages to ports

2018-01-31 Thread Alexander McLin
So I am using Racket's logging facilities in a command-line tool I'm 
developing. I have various defined loggers in a sensible hierarchical 
configuration for use as needed.

During the tool's start up period prior to calling the main function I set 
up a log receiver to receive messages at the desired level and place it 
inside a sync loop within its own thread. Each time a sync event is 
received, it is written out to the port, then loop back to waiting for the 
next sync event.

It works reasonably well except I have a new problem, when the tool exits, 
it often exits before the thread handling the log receiver propagation to 
the port has finished receiving all the log events, as a result my logging 
output is frequently truncated.

Given this undesired situation, I need to figure out a better way to 
reliably propagate all log messages to ports before the tool exits normally 
or due to a raised exception.

There is `with-logging-to-port` except I will need to set up multiple ports 
and the idea of wrapping the tool's main body with multiple 
`with-logging-to-port` for each port isn't appealing and it still doesn't 
resolve the problem.

I was wondering if anyone has a better suggestion? Is there a way to detect 
if there are pending log events waiting to be received by the log receiver?

I realize the fundamental nature of my issue is that Racket's logging is 
asynchronous while I want synchronous behavior. I may be better off just 
using old-fashioned `println`s

Thank you for your suggestions.

Alexander McLin

-- 
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] Apparent Datalog error?

2018-01-31 Thread George Neuner

On 1/31/2018 2:51 PM, Matthias Felleisen wrote:

> On Jan 31, 2018, at 2:15 PM, George Neuner  wrote:
> 
> 
> On 1/31/2018 2:10 PM, Sam Caldwell wrote:

>> Your definition of `ancestor` is one or two steps of parentage:
>> 
>> > ancestor(A, B) :- parent(A, B).

>> > ancestor(A, B) :-
>>   parent(A, C),
>>   parent(C, B).
>> 
>> I suspect you want one of those lines to appeal to the `ancestor` relation to allow longer chains.
> 
> Knowing nothing about datalog he asks naively:
> 
> Shouldn't the ruleancestor(A, B) :- parent(A, C), parent(C, B).   be applied recursively?



It is — except that there’s no recursion.


> Kevin's definition would work in Prolog.


No it wouldn’t.


Sorry ... brain freeze.   Somehow I misread Kevin's code as being

  ancestor(A, B) :- parent(A, C), ancestor(C, B).

which would work.    You and Sam both are absolutely correct that it 
does not work as written.


Apologies for the noise.
George


--
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] Apparent Datalog error?

2018-01-31 Thread Matthias Felleisen

> On Jan 31, 2018, at 2:15 PM, George Neuner  wrote:
> 
> 
> On 1/31/2018 2:10 PM, Sam Caldwell wrote:
>> Your definition of `ancestor` is one or two steps of parentage:
>> 
>> > ancestor(A, B) :- parent(A, B).
>> > ancestor(A, B) :-
>>   parent(A, C),
>>   parent(C, B).
>> 
>> I suspect you want one of those lines to appeal to the `ancestor` relation 
>> to allow longer chains.
> 
> Knowing nothing about datalog he asks naively:
> 
> Shouldn't the ruleancestor(A, B) :- parent(A, C), parent(C, B).   be 
> applied recursively?


It is — except that there’s no recursion. 


> Kevin's definition would work in Prolog.


No it wouldn’t. 

-- 
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] Apparent Datalog error?

2018-01-31 Thread George Neuner


On 1/31/2018 2:10 PM, Sam Caldwell wrote:

Your definition of `ancestor` is one or two steps of parentage:

> ancestor(A, B) :- parent(A, B).
> ancestor(A, B) :-
  parent(A, C),
  parent(C, B).

I suspect you want one of those lines to appeal to the `ancestor` 
relation to allow longer chains.


Knowing nothing about datalog he asks naively:

Shouldn't the rule ancestor(A, B) :- parent(A, C), parent(C, B).   be 
applied recursively?

Kevin's definition would work in Prolog.

George

--
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] Apparent Datalog error?

2018-01-31 Thread Sam Caldwell
Your definition of `ancestor` is one or two steps of parentage:

> ancestor(A, B) :- parent(A, B).
> ancestor(A, B) :-
parent(A, C),
parent(C, B).

I suspect you want one of those lines to appeal to the `ancestor` relation
to allow longer chains.

- Sam Caldwell

On Wed, Jan 31, 2018 at 1:53 PM, Kevin Forchione  wrote:

> Walking through the datalog  tutorial I got the following transcript:
>
> Welcome to DrRacket, version 6.12 [3m].
> Language: datalog, with debugging; memory limit: 512 MB.
> > parent(john, douglas).
> > parent(john, douglas)?
> parent(john, douglas).
> > parent(john, evlyn)?
>
> > parent(bob, john).
> > parent(A, B)?
> parent(john, douglas).
> parent(bob, john).
> > parent(ebbon, bob).
> > parent(john, B)?
> parent(john, douglas).
> > parent(A, A)?
>
> > ancestor(A, B) :- parent(A, B).
> > ancestor(A, B) :-
> parent(A, C),
> parent(C, B).
> > ancestor(A, B)?
> ancestor(ebbon, bob).
> ancestor(bob, john).
> ancestor(john, douglas).
> ancestor(bob, douglas).
> ancestor(ebbon, john).
> >
>
> It seems that the correct answer should also include ancestor(ebbon,
> douglas). Am I doing something wrong?
>
> -Kevin
>
>
> --
> 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.
>

-- 
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] Apparent Datalog error?

2018-01-31 Thread Kevin Forchione
Walking through the datalog  tutorial I got the following transcript:

Welcome to DrRacket, version 6.12 [3m].
Language: datalog, with debugging; memory limit: 512 MB.
> parent(john, douglas).
> parent(john, douglas)?
parent(john, douglas).
> parent(john, evlyn)?

> parent(bob, john).
> parent(A, B)?
parent(john, douglas).
parent(bob, john).
> parent(ebbon, bob).
> parent(john, B)?
parent(john, douglas).
> parent(A, A)?

> ancestor(A, B) :- parent(A, B).
> ancestor(A, B) :-
parent(A, C),
parent(C, B).
> ancestor(A, B)?
ancestor(ebbon, bob).
ancestor(bob, john).
ancestor(john, douglas).
ancestor(bob, douglas).
ancestor(ebbon, john).
> 

It seems that the correct answer should also include ancestor(ebbon, douglas). 
Am I doing something wrong?

-Kevin


-- 
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-01-31 Thread Greg Hendershott
Another way is for two (OS) processes to "pipe" I/O to each other.

The back-and-forth "protocol"?

It could be as simple/ad-hoc vs. as formal/ceremonial as you prefer.

It could be text line-oriented, or JSON, or s-expressions, or raw bytes.


I might use this as a starting point, get some mileage, then decide if
it's adequate or what to do instead.

p.s. If you squint and abstract away certain details, this is similar
to the HTTP service approach.

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


[racket-users] Re: How to integrate Racket with a .Net application?

2018-01-31 Thread Alexander McLin
All three approaches you outlined are viable but web service is easiest to 
set up. 

>From what you described, it seems it would be a low-performance use for 
Racket and only simple data structures will be passed back and forth on an 
infrequent basis. Web service would be a good fit for that.

Out of the last two approaches, the COM approach seems to me to be the 
better one. Although I have never used it, Racket provides MzCOM and .NET 
comes with additional support for interacting with COM from within the .NET 
environment. It would allow you to tightly integrate Racket into your 
application, pass complex data back and forth and achieve higher 
performance throughout, but likely it would be more work. I've used COM in 
the past for C++ applications; in those projects it was always a lot of 
work to configure and integrate COM.

I would try setting up a web service first and if it's not adequate for 
whatever reason (performance, business requirements, etc) then I would try 
the COM approach.

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


[racket-users] How to integrate Racket with a .Net application?

2018-01-31 Thread Daniel Brunner
Hello:

We have an application on Windows that can be extended with .Net
components (DLL). We mostly use C# for this purpose. Our idea now is to
"embed" Racket into one of these components.

After reading the documentation of the FFI and de C API I am unsure what
may a good way to accomplish that. Has anybody done something like this
or has an implementation idea?

We want to push some basic data (lists of structs, strings, numbers
etc.) to a Racket component, trigger some functions and get some result
back. This action is triggered by user input once in several days.

There are several ways I am thinking about:

- establish some sort of web service (talking JSON over HTTP)
- use the C API
- use the libraries for COM objects

Any advice or ideas would be greatly appreciated!

Best wishes,
Daniel

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