Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Look at my program: Its a server

Name: Anonymous 2015-02-10 0:47

In the spirit of wanting to see more programs on this board, I am posting this programlet. Its the beginnings of a server so I can talk to my universe LispM program as though its a BBS through a terminal program like putty.

Please post your programs as also well too mutually also together. I would like to see them. If they are graphical or audioful or gameful or simulationful programs are preferred, but of course, post any program.

Don't forget to comment, rate and subscribe.

WISHFUL THINKING

function svrRunLuaPromptServer(sck)
local s = svrReceive(sck)
if s ~= "" then
luaCall(s)
local err = getErrorText()
if err ~= "" then
svrSend(err, sck)
clearError()
end
-- svrSend("Ready.\n")
--svrSend("\n> ")
svrSend("> ", sck)
end
end

function svrRunEchoServer(sck)
-- echo server
local s = svrReceive(sck)
if s~="" then
clearTrace()
for i=1,#s,1 do
print(string.byte(s,i))
end
end
svrSend(s, sck)
end

function initServer()
svrStart()
print("Server started")
coroutine.yield()

print("Waiting for terminal client...")
repeat
sck1 = svrAccept()
coroutine.yield()
until svrIsValidSocket(sck1)

print("Terminal client connected.")

svrSend("You are the lua prompt terminal\n> ", sck1)
coroutine.yield()

print("Waiting for echo client...")

repeat
sck2 = svrAccept()
coroutine.yield()
until svrIsValidSocket(sck2)

print("Echo client connected.")

svrSend("You are the echo terminal", sck2)
end

function restartServer()
initServerRoutine = coroutine.create(initServer)
coroutine.resume(initServerRoutine)
end

if initServerRoutine == nil then
restartServer()
end

function update()
if coroutine.status(initServerRoutine) ~= "dead" then
coroutine.resume(initServerRoutine)
else
svrRunLuaPromptServer(sck1)
svrRunEchoServer(sck2)
end
end

Name: Anonymous 2015-02-10 9:27

>>1
That's quite fascinating OP. Your use of coroutines is elegant and understated. It seems like the "echo server" could be the beginnings of a tty screen editor.

Name: Anonymous 2015-02-10 9:44

function
function
function

What kind of shitty language has reserved words 8 letters long? Moreover, it's one of the most frequently used reserved words! Why not "fun", why not "fn", why not "defun" for fuck's sake?

Name: Anonymous 2015-02-10 9:46

>>3
why not a symbol instead of being bogged down to ascii shit?

Name: Anonymous 2015-02-10 10:15

>>3,4
Your replies depress me.

Name: Anonymous 2015-02-10 11:20

>>4
Works too, but you have to be careful not to turn into an APL or Agda.

Name: Anonymous 2015-02-10 13:54

putty
You mean I have to install wine to use it?

Name: Anonymous 2015-02-10 18:01

check 'em fibs

Name: Anonymous 2015-02-10 19:42

>>3,4
Syntax is not code.
Code is structure. Syntax is irrelevant.

Name: Anonymous 2015-02-10 20:10

#include <stdio.h>
int main(){if(printf("Hello!\n")){}}


Look, mom, no semicolons!

Name: Anonymous 2015-02-10 20:36

>>12
Check these dubs.

Name: Anonymous 2015-02-10 20:43

fuck off

Name: Anonymous 2015-02-11 4:47

>>12
No U
>>11
Nice one.

I am waiting to hear compliments.

Name: Anonymous 2015-02-11 5:40

>>13
That's a nice server, but I doubt that you're >>1​-san

Name: Anonymous 2015-02-11 6:54

>>9
syntax is only irrelevant if you never have to read or write code

Name: Anonymous 2015-02-11 8:17

>>15
This one is right.

>>9
This one is wrong because not even a programmer.

Name: Anonymous 2015-02-11 8:55

>>14
This is >>1-san. Here is a tty text viewer for the echo server, on its way to becoming a tty text editor.

first_visible_line = 1
first_visible_column = 1
buffer = ""
position = 1
screenstring = "line 1\nline 2\nline 3\n"

csi = string.char(27) .. "["

function move_cursor(x,y)
svrSend(csi .. x .. ";" .. y .. "H")
end

function clear_screen()
svrSend(csi .. "2J")
end

-- stile di pensiero desideroso

function position_to_line(s, pos)
for i=1,pos,1 do

end
end

function position_to_linecol(pos)
end

function linecol_to_screen(pos)
--
end

function screen_to_linecol(line,col)
end

function linecol_to_position(line,col)
end

function handle_up()
first_visible_line = first_visible_line - 1
if first_visible_line < 1 then
first_visible_line = 1
end
draw_string(s)
end

function handle_down()
first_visible_line = first_visible_line + 1
if first_visible_line < 1 then
first_visible_line = 1
end
draw_string(s)
end

function handle_left()
first_visible_column = first_visible_column - 1
if first_visible_column < 1 then
first_visible_column = 1
end
draw_string(s)

position = position - 1
if position < 1 then position = 1 end
--draw_string(screenstring)
end

function handle_right()
first_visible_column = first_visible_column + 1
if first_visible_column < 1 then
first_visible_column = 1
end
draw_string(s)

position = position + 1
if position > s:len() then position = s:len() end
end

function handle_key(k)
-- insert character into string
end

function draw_string(s)
-- set cursor to 1,1
-- write string to console starting from the
-- first_visible_line until first_visible_line+num_visible_lines
-- or the end of the string, whichever is first.
-- also from first_visible_column until num_visible_columns

--local cx = 1
--local cy = 1
move_cursor(1,1)
clear_screen()
local s2 = s
if s2:byte(s2:len()) ~= 10 then
s2 = s2 .. "\n"
end
local linenum = 1
for line in s2:gmatch('([^\n]*)\n') do
if linenum >= first_visible_line and linenum < first_visible_line + 20 then
svrSend(line:sub(first_visible_column, first_visible_column + 50).."\n")
end
linenum = linenum + 1
end
end

lastkey = {}

function svrRunEchoServer(sck)
-- echo server
local s = svrReceive(sck)
-- detect up, down, left, right, backspace, delete, insert, etc
-- shift arrows, more and more and more
if s~="" then
clearTrace()
lastkey = {}
for i=1,#s,1 do
print(string.byte(s,i))
table.insert(lastkey, string.byte(s, i))
end

local handled = false

if #lastkey==3 then
if lastkey[1] == 27 and lastkey[2] == 91 then
if lastkey[3] == 65 then
handle_up()
handled = true
end
if lastkey[3] == 66 then
handle_down()
handled = true
end
if lastkey[3] == 67 then
handle_right()
handled = true
end
if lastkey[3] == 68 then
handle_left()
handled = true
end
end
end

if handled == false then
svrSend(s, sck)
end
end
end

function showkey()
for i=1,#lastkey,1 do
svrSend(""..lastkey[i],sck1)
if i<#lastkey then
svrSend(",", sck1)
end
end
svrSend("\n",sck1)
end

function make_lines(s)
local lines = {}
for line in s:gmatch('([^\n]*)\n') do
-- svrSend("->" .. line .. "\n", sck1)
table.insert(lines, line)
end
return lines
end


Note the deranged comment in italian, and the incomplete functions. These are signs of a mind that has damaged itself by reinforcing pleasure pathways so often that it satisfies itself too soon, so soon that it won't even make the minimum effort to finish something that would take about 3 minutes of mild concentration.

I made praxis so I could experience flow at any time. Flow when making a midi recorder. Flow when making a server I can change at a whim. And I still find it difficult to devote the tiny amount of energy it would take to make things with it. Instead I browse the retarded intertubes and read and get distracted with bullshit because the habits are such a powerful attractor, these shitty distractions are the new steady state of my brain.

HALP

Name: Anonymous 2015-02-11 19:14

>>15,16
Syntax is only relevant if you are a total beginner. Like written language, it is the semantics that actually matter. Clearly you have a long way to go before reaching Satori.

Name: Anonymous 2015-02-11 19:22

>>18
Syntax is important because that is what the programmer's eyes are looking at whenever he's reading code. It's a perpetual overhead for visual decoding of program text. Once you start dealing more with actually writing and refactoring programs (instead of posting on crappy forums), you'll see that syntax really is all-important, and every letter saved on a frequently-used reserved word is a burden off your brain.

Clearly you have a long way to go before becoming a real programmer.

Name: Anonymous 2015-02-11 19:29

>>18
Also, in written language, people care about syntax quite a lot, too. There's a reason we start sentences with capital letters and end them with short, concise punctuation signs. Also, people care a lot about such non-semantic things like fonts and typesettings for the same reason. It's much easier to read large amounts of text (like books) that way. Do you read books very often? Probably not.

Name: Anonymous 2015-02-11 19:45

>>19
I agree to a point. However, it is vertical brevity that is the saviour of time and mental effort.
A Java program on an 80x24 terminal will be much more difficult to grok than the equivalent in Scheme, even if Scheme's identifiers are mostly long, descriptive words -- purely because of having to scroll and look up and down in order to get the whole thing in memory.

I would argue, in fact, that horizontal tersity is more of a mental burden. Consider the ebb and flow of human language: the average word is likely over five characters in length, and it is the shorter words -- a, on, the -- that add no meaning. Their purpose is to add structure rather than to mould the ideas flowing from the text.
function, as a keyword, is seeped in meaning, and not actually particularly oft-used compared to int or set (for instance), so its right as a long-ish identifier is earned -- plus syntax highlighting gives you at-a-glance information without even having to actually read the word. Cbmnieo tath whti teh mndi's ucnyann caaipcty to rdea ttlyloa srmclbdea txte, and there is absolutely no reason to shave a letter off a semi-frequently used identifier for the purposes of mental processing.

So please, quit your ad hominem attacks and baseless assumptions, and acknowledge that your fervent assertion that fun is irrefutably superior to function is massively autistic.

Name: Anonymous 2015-02-11 20:02

>>20
You're going off track. The human mind is wonderfully flexible. Did you know, I could leave out the capital letters and question mark from this sentence and it would cause no measurable hinderance to your digesting it as a condescending rhetorical question?
Typesetting is irrelevant to the different syntaxen used in different languages, and you know it. I use one font in my terminal, and I chose it. I didn't choose Lua's keywords and I can deal with that. There are studies on eye strain in the context of serif and sans-serif fonts on screen and paper, and there is a correlation. There is nothing in response to "FIOC looks worse to me than open and closed braces" except "shut the fuck up you whiny bitch and get back to work".

Name: Anonymous 2015-02-12 1:21

>>7 Putty isn't just for Windows

Name: Anonymous 2015-02-12 3:47

>>1,17
Neat! But you may want to secure it before using it across the open net.

Name: Anonymous 2015-02-12 4:18

An open letter to /prog/.

Please stop being shitty.

If someone insults you, you don't need to generate 20 posts in a row in a text fight about nothing.

Please stop insulting people, as it leads to these exchanges.

Post fun and happy things, and programs, please.

Signed,
••••••

Name: Anonymous 2015-02-12 4:41

>>24
No need to worry, I've just been connecting to localhost.

Name: Anonymous 2015-02-12 5:23

>>25
Signed,
••••••
What the hell kind of weird ass name is that? How does one pronounce such a name?

Name: Anonymous 2015-02-12 6:50

>>27
It's morse code. da-da-da-da-da-da.

Name: Gromov 2015-02-12 10:28

>>21
function, as a keyword, is seeped in meaning
Really? And what meaning would that be? There is none, its purpose is precisely "to add structure rather than to mould the ideas flowing from the text" - quoting none other than you!

plus syntax highlighting
Not always available, especially on the web.

Anyway, even in the presence of syntax highlighting, having a long, 8-letter word to define a function has a real drawback: the reader has to shift his vision by a lot of characters just to get to the function's name and parameters. This is just visual boilerplate that the reader has to overcome for every function definition. Of which there are over 15 just in >>17. So I think that reducing the reserved word to something short like fun would do a lot of good in brain power savings for anyone who reads the code.

Cbmnieo tath whti teh mndi'
Stop speaking Cthulhu. What does that mean?

So please, quit your ad hominem attacks
It was you who started with ad hominem. I was originally attacking only the shitty language, not anyone in particular.

>>22
Did you know, I could leave out the capital letters and question mark from this sentence and it would cause no measurable hinderance to your digesting it as a condescending rhetorical question?
Yes, it would cause a measurable hinderance. A hinderance that becomes all the more noticeable with large amounts of text to be read.

Typesetting is irrelevant to the different syntaxen used in different languages
It is another example of something that doesn't affect semantics but is very important to reading.

>>25
But we haven't generated 20 posts in a row in a text fight about nothing. It was about about a very important problem.

Don't change these.
Name: Email:
Entire Thread Thread List