## Handling 'write!' procedures for custom binary output ports

scheme

### Next

• 1. lambda and define
Hello schemers, My understanding, after going through initial chapters of SICP, of define was that it is lambda in disguise. However, this code piece (trying the solution to ex. 3.7 ed.1) does not work as expected and I had to replace the define with lambda. (define (estimate-integral x1 x2 y1 y2 trials) (define experiment (p (real-random x1 x2) (real-random y1 y2))) (* (rect-area x1 x2 y1 y2) (monte-carlo trials experiment))) The trace of the procedure showed that the experiment was getting evaluated before calling the monte-carlo. When I replaced the experiment with this code, it worked as it passed the procedure instead of the value of the procedure (define (estimate-integral x1 x2 y1 y2 trials) (let ((experiment (lambda() (p (real-random x1 x2) (real-random y1 y2))))) (* (rect-area x1 x2 y1 y2) (monte-carlo trials experiment)))) If lambda and define are one and the same then how come the evaluation points are different? Any explanation is really appreciated.
• 2. creating a list from console inputs
I want to create a list from numbers that the user gives through keyboard. The list is done when user hits a predefined key e.g 'q'. Any good ideas?
• 3. Possibly OT: Reasoned Schemer
Hi, I'm slogging through "The Reasoned Schemer", by Friedman, Byrd, and Kiselyov. After getting lost a couple times, and restarting the book a couple times, I'm seeing the hint of a suggestion of enlightenment in its pages. At least I was until I came across this: 1.54 pp 13 What is the value of (run* (r) (fresh (x y) (conde ((== split x) (== pea y)) ((== navy x) (== bean y)) (else #u)) (== (cons x (cons y ())) r))) > ((split pea) (navy bean)) Now, this is bothering me because I would have thought that the answer would be ((split navy) (pea bean)) because we are associating x with split then navy, and y with pea then bean, but this is obviously incorrect. Can anyone with help me out with what's going on here? Thanks! -Jason

### Handling 'write!' procedures for custom binary output ports

Hello,

Could someone help to explain some of the wording for R6RS reagarding
custom binary output ports?

The specification of the writer for the custom port indicates that when
passed a count of zero, this should be the same as asking the write
procedure to send the eof of file "object" to the byte sink. However, the
R6RS EOF object defined by R6RS is that object returned by 'eoj-object',
which by definition has no external representation and is not a datum.
Moreover, the write procedure is required to indicate the number of bytes
that were actually written. This number should not be, according to my
reading, more than the count argument that is passed to the write
procedure. Yet, in the case of the zero count argument, we are required to
write something, which means at least one byte, to the byte sink. This to
me indicates that the write procedure must return at least 1 in all cases.

There are two traditional EOF characters in common use today, the CTRL-D
from UNIX, and the CTRL-Z from windows. Does R6RS actually mean that one
of these characters should be send to the sink? If so, which one? Should
be base this on the platform which is sending the data, or the platform of
the system receiving the data? These can be different systems, as in the
case of sockets or network communication, and thus, who knows whether one
or the other should be considered?

Additionally, there is no facility for sending this character outside of
using something like #\x4 to send it. If R6RS really intended to use a
character for sending the EOF object over the
stream or byte sink, wouldn't it make sense for the R6RS to at least
define the #\eof or #\end-of-file character so that this could be done in
a portable way. Even without this, at least something like an
'eof-character' parameter could have been made.

The complete lack of information available on this in the documents
suggests that I have misread something. Could someone provide more input
as to the proper behavior of these procedures when they are passed a zero
value for their count argument?

As a side, I also know that in Linux, the write(2) system call has
unspecified behavior with a zero count argument when the file descriptor
is not a regular file.

Aaron W. Hsu

--
Of all tyrannies, a tyranny sincerely exercised for the good of its
victims may be the most oppressive. -- C. S. Lewis


### Re: Handling 'write!' procedures for custom binary output ports



That makes absolutely no sense.  I'd suggest you just ignore it.

The same language for custom textual output ports makes no sense
either, in my opinion.  I'd suggest you ignore it too.

Both of these mistakes were in the 5.92 draft.  I did a fairly
complete rewrite of the i/o library a few days before that
draft was published, so these mistakes are probably my own.
I apologize for these mistakes, and hope they will be removed
by a superseding document.

Will


### Re: Handling 'write!' procedures for custom binary output ports

On Fri, 31 Jul 2009 20:03:34 -0400, William D Clinger < XXXX@XXXXX.COM >

So what is the behavior? The same as write(2), that is, unspecified?

Aaron W. Hsu

--
Of all tyrannies, a tyranny sincerely exercised for the good of its
victims may be the most oppressive. -- C. S. Lewis


### Re: Handling 'write!' procedures for custom binary output ports



The prescribed behavior, being nonsensical, is effectively
unspecified.

I'm suggesting that your write! procedure should do nothing
when passed a count of zero.  It's a custom port, so its
behavior is entirely up to you, and you can interpret the
count in arbitrarily bizarre ways without fear of being sued
by language lawyers.

Will


### Re: Handling 'write!' procedures for custom binary output ports

On Sat, 01 Aug 2009 09:00:32 -0400, William D Clinger < XXXX@XXXXX.COM >

learn to check that first. :-) Unless it was added very recently.

Aaron W. Hsu

--
Of all tyrannies, a tyranny sincerely exercised for the good of its
victims may be the most oppressive. -- C. S. Lewis


Hi,

I need to write binary data to a serial port. I am using this function:

#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count);

I am able to write a alpha-numeric character to the port using this:

write (filedescriptor,"a",1);

But I want to write a byte of 1's and 0's to this port. For examples, I want
to write 00000011 to this file descriptor.

How do I do this?

Many Thanks!!

Regards,
Tom



I seem to be tying myself up in knots.  I have written some VHDL to read
from a binary file and this works fine.

I'm now trying to write binary data to a file and would be grateful for a
steer.  I have looked at "write" and "writeline" but these seem to output
bit to string conversions instead of a pure binary file.

Would be grateful for some help.



Sharp, thanx for the wonderful explaination related to bi-directional
ports declaration. I was trying the exact same thing where I stored
the 32-bit value in an intermediate register within always @(..) block
and used using a continuous assignment statement outside the always
block. And it works fine!

However, the other solution using the Conditional assignment statment
instead of the always @(..) block doesnt work.. Let me try that again
and see where the error is....

Get back to you soon,
Thanx alot again


Hello everyone,

I am facing problems making an output-port to a bi-directional port.

//////////////////////////////////////////////////////
///// (A) Here is the code, which compiles correctly:
/////////////////////////////////////////////////////

input 	clock;
input 	WE;
input 	RE;

reg 	[7:0] A;
reg	[7:0] B;
reg 	[7:0] C;
reg 	[7:0] D;

reg E,F;

always @(posedge clock)
begin
if (E==F)
begin
end

end
end
endmodule

/////////////////////////////////////////////////////////////////
//// (B) Here is the Code, which gives the error as shown below:
////////////////////////////////////////////////////////////////

input 	clock;
input 	WE;
input 	RE;

inout 	[31:0] AD;  // Note: This gives error when AD declared as
inout-port //

reg 	[7:0] A;
reg	[7:0] B;
reg 	[7:0] C;
reg 	[7:0] D;

reg E,F;

always @(posedge clock)
begin
if (E==F)
begin
//// The error is shown at this line saying Incompatible inout port
////
end

end
end
endmodule

I tried the following but none of them compiled:

(1) I know that Inout-ports both internally & externally must always
be net type. So I declared:  <wire [31:0] AD >  in (B) above

(2) The LRM clearly says that any continuous assignment within any
procedural-statements, namely always (or) initial, has to be a
register, So retained AD as reg while it was declared inout-port.

(3) I also rememeber reading earlier that the Conditional-assignment
needs to be used for bi-directional ports.

So I replaced the above always @(..) block to a conditional assignment
as below:

assign AD 	= (E==F) ? {A,B,C,D} : 8'hzzzzzzzz;

Is there soemthing very obvious, I am missing!!


I'm looking for a way to use I/O dispatching (provided by poll(2) or
WaitForMultipleObjects()) and task entries together.  In some way,
this resembles a custom interrupt facility.

For example, a gateway which passes data back and forth between a
client and a server (over full-duplex connections) could be structured
like this:

entry Client_Activity (Socket : File_Descriptor);
entry Server_Activity (Socket : File_Descriptor);
entry Statistics (Requests, Clients : out Natural);
end Server;

begin
loop
select
accept Client_Activity (Socket : File_Descriptor) do
--  Do something when data from the client arrives.
null;
end;
or
accept Server_Activity (Socket : File_Descriptor) do
--  Do something when data from the server arrives.
null;
end;
or
accept Statistics (Requests, Clients : out Natural) do
Requests := 0;
Clients :=0;
end;
end select;
end loop;
end Server;

This example does not include the attach/detach operations which
control which file descriptory activity is signaled on which entry.
I use a task (and not a protected object) because more than one
gateway should run in the same process.

If Server only had to wait for file descriptor activity, it would be
easy.  I'd just call the appropriate system call (probably poll(2)).
However, I can't do that if I want to have other entries, too.

I wonder how I could implement this efficiently.  Obviously, I need
some dispatcher task which performs the actual call to poll(2), and
protected objects that record pending file descriptor activity (Server
might not be able to accept the entry call at once, but the dispatcher
task must not block).  And I need hand-written wrapper procedures for
the Client_Activity and Server_Activity entries because there is no
way to refer to these entries directly, using access values or
generics.

--
Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: atlas.cz, bigpond.com, postino.it, tiscali.co.uk,
tiscali.cz, tiscali.it, voila.fr.