[ art / civ / cult / cyb / diy / drg / feels / layer / lit / λ / q / r / sci / sec / tech / w / zzz ] archive provided by lainchan.jp

lainchan archive - /λ/ - 8491



File: 1439511436822.png (23.45 KB, 300x50, greetings-to-the-user.png)

No.8491

Here's a challenge I find more interesting than the fizzbuzz seen so often: Greetings to the User

You are to write a program that does the following:
Print "What is your name? "
Read input from the user.
Print "Greetings, %s." where %s is the aforementioned input.

Try to make it as small as possible for more fun. Let's see who can write the shortest solutions in the different languages.

Forth (65 chars):
." What is your name? "pad dup 9 accept ." Greetings, "type ." ."

Common Lisp (65 chars):
(princ"What is your name? ")(format t"Greetings, ~a."(read-line))

Emacs Lisp (58 chars):
(format"Greetings, %s."(read-buffer"What is your name? "))

I consider this to be a better metric for judging languages than the simple hello world. It certainly shows more characteristics of the language.
I wonder what variety we'll see here.

  No.8494

This is even more basic than FizzBuzz though.

Python (53 chars):
print("Greetings, %s" % input("What's your name? "))

  No.8513

Javascript (54 chars):

alert('Greetings, '+prompt('What is your name?')+'.');


Perl (57 chars):

print "What is your name?\n";$_=<>;print "Greetings, $_";


>>8494
It's on par with Hello World.

  No.8527

Haskell 73 bytes
putStr"What is your name? ">>getLine>>=putStrLn.("Greetings, "++).(++".")

  No.8528

>>8527
same
do{putStr"What is your name? ";n<-getLine;putStrLn$"Greetings, "++n++"."}

  No.9996

APL 45 characters:
⍞←'What is your name? '⋄⍞←'Greetings, ',⍞,'.'

  No.10003

File: 1443604195353.png (262.88 KB, 200x180, strongest_programmer.png)

C++ (160 chars):


#include <string>
#include <iostream>
int main(){using namespace std; string s;cout<<"What is your name? ";getline(cin,s);cout<<"Greetings, "<<s<<".";return 0;}


Just for comparisons.

  No.10009

echo Greetings, ${1}.

save as "What is your name?.sh"

  No.10012

>>10009
cheater

  No.10014

>>10009
>>10012
Can't really say it's cheating when you can do it with any executable, not limited to shell scripts. It just doesn't count if you have to type the question yourself.

  No.10015


print("Greetings,", input("What is your name?"))

  No.10030

>>10009
This is nice and all, but it doesn't actually print "What is your name? ".

It also doesn't work if your input has spaces, which could happen if you enter your entire name.

I'm not trying to be too critical though. This is still neat.

  No.10185

File: 1444097584956.png (230.14 KB, 200x113, 8K9r7vb.jpg)

>>10003

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *arv[])
{
size_t maxlen = 128;
char *name;
printf("%s\n", "What is your name?");
printf("Greetings, %s", getline(&name, &maxlen, stdin) ? name : "kek");
return 0;
}

  No.10216


echo 'What is your name?' && read OUT
echo 'char c[] = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05";int main(int a,char**v){(*(void(*)())c)();}' | \
gcc -x c - -fno-stack-protector -z execstack -o name && echo "echo Greetings, $OUT" | ./name

  No.10217

>>10015
python is sexy as fuarrrk

  No.10220

>>8491
>Caring about source size, not binary size

It's a while since I did ARM assembly, but this should do the work. You need at least a linux kernel to run this.

[code]
.global _start

_start :
MOV r0, #1
ADR r1, what
MOV r2, whats
MOV r7, #4
SVC 0

MOV r0, #0
ADR r1, name
MOV r2, names
MOV r7, #3
SVC 0
MOV r0, r8

MOV r0, #1
ADR r1, greet
MOV r2, greets
MOV r7, #4
SVC 0

MOV r0, #1
ADR r1, name
MOV r2, r8
MOV r7, #3
SVC 0

MOV r0, #1
ADR r1, newl
MOV r2, #1
SVC 0

MOV r7, #1
SVC 0

.data
what: .asciz "What is your name ? "
whats: .equ 20
greet: .asciz "Greetings, "
greets: .equ 11
newl: .asciz "\n"
name: .fill 20
.align 2
names: .equ 20
[\code]

  No.10221

>>10220
Well, soykaf .
This should be better.

.global _start

_start :
MOV r0, #1
ADR r1, what
MOV r2, whats
MOV r7, #4
SVC 0

MOV r0, #0
ADR r1, name
MOV r2, names
MOV r7, #3
SVC 0
MOV r0, r8

MOV r0, #1
ADR r1, greet
MOV r2, greets
MOV r7, #4
SVC 0

MOV r0, #1
ADR r1, name
MOV r2, r8
MOV r7, #3
SVC 0

MOV r0, #1
ADR r1, newl
MOV r2, #1
SVC 0

MOV r7, #1
SVC 0

.data
what: .asciz "What is your name ? "
whats: .equ 20
greet: .asciz "Greetings, "
greets: .equ 11
newl: .asciz "\n"
name: .fill 20
.align 2
names: .equ 20

  No.10227

>>10003
C++ 126 chars

#include<iostream>
#include<cstdio>
int main(){char s[99];puts("What is your name?");std::cin>>s;printf("Greetings, %s",s);}

  No.10231

Scheme

(import (scheme base))
(begin (display "What is your name? ") (display (string-append "Greetings, " (read-line) ".\n")))

  No.10244

Scala:


printf("Greetings, %s.", readLine("What is your name? "))

  No.10638

Go (143 chars):

package main

import "fmt"

var n string

func main() {
fmt.Print("What is your name? ")
fmt.Scanln(&n)
fmt.Printf("Greetings, %s.\n", n)
}


>Your request looks automated; Post discarded.

Piece of soykaf imageboard engine.

  No.10645

What exactly is the point of this anyways? The compiler/interpreter most likely brings it all down to the same stuff anyways, so is this just a formatting thing?

>I find more interesting than the fizzbuzz


Why? They are two different things. Fizzbuzz is to check math and logic capabilities (modulus, loops) while this is just reading user input, and dicking around with strings.

  No.10646

>>10645
>What exactly is the point of this anyways?
Fun and fascination, mostly.

>The compiler/interpreter most likely brings it all down to the same stuff anyways, so is this just a formatting thing?

I wouldn't say that. I can tell you for a fact that isn't the case with the Forth.

>>I find more interesting than the fizzbuzz

>Why? They are two different things. Fizzbuzz is to check math and logic capabilities (modulus, loops) while this is just reading user input, and dicking around with strings.
It's neat to see a program written different ways in different languages. Fizzbuzz focuses on certain aspects but is also really common by now.
This focuses on how different languages deal with I/O and string manipulation, which is fun to see.
If you can think of a similar small program we can write to look at the differences in languages and different implementation techniques therein, feel free to suggest it. I know I would participate.

  No.10653

>>10646
I don't really have any firm suggestions, but maybe something that dealt with user input, then some math stuffs, maybe some casting, then string manipulation and output?

  No.10657

>>10646
>>10653
I will be quite unoriginal here. FizzBuzz that takes a number input from user.

  No.10660

>>10657
Not usually. The form I have seen it in is for numbers 0 through 100, but you could add the user input if you want.

  No.10661

What I normally do to quickly test a language is to take a string and return the phonetic alphabet equivalent of it.


./phon hello
HOTEL ECHO LIMA LIMA OTHELLO

  No.11104

Rust:


use std::io::{self, Write};

fn main() {
let stdin = io::stdin();
let mut stdout = io::stdout();
print!("What is your name? ");
stdout.flush().unwrap();
let mut name = String::new();
stdin.read_line(&mut name).unwrap();
println!("Greetings, {}.", (&name).trim());
}

  No.11111

Python3, 58 characters:
print('Greetings, {}.'.format(input('What is your name? ')

  No.11148

>>11111

print("Greetings, "+input("What is your name?"))


48.

  No.11154


// gcc hello.c -lreadline
#include <stdio.h>
#include <readline/readline.h>

int main() {
printf("Greetings, %s\n", readline("What is your name? "));
}

  No.11156

Ruby:
puts "What is your name?"
name=gets.chomp
puts "Greetings, " + name.to_s

70 chars

  No.11158

>>11148
Nice. I assume that this works because the class of the object returned by input() is str, so the two strs can be concatenated directly, without the need to wrap input() in format()?

  No.12717

There's a nice variety of languages by now. I haven't tried thinking of anything else we could do yet.
>>10661
Unless I'm mistaken, this just looks like making a database and printing the corresponding word for each letter key.

  No.12731

QuickBasic


DIM x AS STRING
INPUT "what is your name? ", x
PRINT "Hello " + x

  No.12733

C - 81 chars.
main(){char a[99];puts("What is your name?");gets(a);printf("Greetings, %s",a);}


The compiler gives a few warnings but it still compiles.

  No.12778

Ruby

print "What is your name ? ";a=$stdin.gets.chomp;puts "Greetings,#{a}"

  No.12797

Common Lisp, but this time in one line. 59 characters.
(format t "What is your name?~%Greetings, ~a." (read-line))

  No.12798

>>12797
I'm OP and that won't work.
FORMAT will want the value of the READ-LINE call before it interprets the control string.

  No.12799


p=process;l=console.log;l("What is your name?");p.stdin.on('data',function(i){l("Greetings, "+i);p.exit()})

107 chars oneliner in Node

Event based io isn't really optimized for minimization.

  No.12814

>>12798
Ah yes, I was being dumb there.

  No.13061

Pretty sure this is the shortest you can get with Ruby, unless I'm missing something. 49 characters.

print"What is your name? ";puts"Greetings, "+gets

  No.13079


>>8491
Python

name = raw_input("Enter your name: ")
print "Friendly greetings %s." %name

  No.13102

Lua (60 Chars)
print"What is your name?" a=io.read() print("Greetings "..a)

  No.13106

>>13079

or just
print "Friendly greetings %s." %raw_input("Your name: ")

  No.13127

>>12733
works
int a[99]; brings it down to 80

  No.13154

>>12733
Doesn't this allow for a buffer overflow?

  No.13171

File: 1451679355180.png (629 B, 27x27, Lain.png)

Piet, 27x27px.
I could make it fit in less space but honestly I spent enough time on it as it is.
Tested it on PietDev and npiet.

>> npiet -q Lain.png
What is your name? Lain.

Greetings, Lain.

You have to put a dot at the end of your name to make it work. Other implementations often change things so using a dot is all I could think of.
I can explain how the code works, if anybody's interested.

  No.13172

>>13106
Didn't know you could do that. Thanks PyWizard

  No.13175

>>13171
> I can explain how the code works, if anybody's interested.
Please do.

  No.13177

>>13175
Alright. Piet is a LOT like Forth, so read up on it if you don't know how Forth works.
Piet evaluates the difference of colour and darkness on tiles in a straight line until it hits a black tile/wall, which will make it rotate clockwise until it hits a tile it can evaluate, or a pointer (POI), which will rotate it clockwise as many times as the first element of the stack is. Piet only deals with numbers, so every stack element is a number.
First part is boring, I just obtain 100 and juggle it back and forth to obtain the characters I need to print.
Then there's a loop in the 2px high line:

PUSH # add a counter to the stack
# loop start
INCHAR
(46) PUSH(2) # simplification: there's some boring operations to obtain 46
PUSH PUSH ROLL # switch the first and second elements of the stack
MOD # 46 % $char, which means that an ETB will work just as well
NOT NOT # negate the output of the prev operation twice to get either 0 or 1
POI
# dp1: (rotates to the right)
(2) PUSH PUSH ROLL # same as before
PUSH ADD # increase the counter
# and then it loops back
# dp0: goes on with the program

Note that when I use PUSH(2) I mean that the PUSH block is 2px big, not that I push a 2 to the stack.
Then there's some more boring code to print "Greetings, ", and the final loop:

# loop start
DUP PUSH(2) PUSH SUB ROLL # use the counter to get stack[-1]
OUTCHAR PUSH SUB # print letter letter and decrease counter
DUP PUSH GREATER POI # check if the counter is greater than one
# dp1: loops back to the start
# dp0: print a dot and a newline and quit

  No.13284

'What is your name? '. name := stdin nextLine. 'Hello '. name.
First day trying smalltalk, so I'm sure it's easier.

Think that's 63 chars.

  No.13285

>>13171
couldn't you put a newline/enter/carriage return instead of a dot?

  No.13296

>>13285
I guess. I used PietDev to debug it, and PietDev's input box acts in a different way from npiet, and by the time I thought about it I had already finished writing the program.
I made it in a very stupid way, if I want to change a single thing I'd have to change all the colours ahead.
If you ever write Piet, do not do this.

  No.13297

Does anyone actually test theirs, i've tested a couple and they have failed.

  No.13298

>>13297
I'm OP and I've tested mine, of course.

  No.13331

>>13284

Smalltalk
'What is your name? '.n:=stdin nextLine.'Greetings, ',n.
Revised and actually proper now. Ruby says 56 chars. Same person as the referred post.

  No.13332

>>13331

Nope, I missed the period.

Smalltalk
'What is your name? '.n:=stdin nextLine.'Greetings, ',n,'.'.
60 chars

  No.13333

>>13332


Smalltalk
'What is your name? '.'Greetings, ',stdin nextLine,'.'.
Removed the unnecessary variable, 55 chars.

  No.13334

Ruby
p'What is your name? ';'Greetings, '+gets.chomp+'.'
51 chars

  No.13359

>>13333
It doesn't follow the specs though quads man.

  No.13367

>>10030
>doesn't work if your input has spaces
$*

  No.13368

>>13172
>not knowing that anything that evaluates to a string can be used as a string, because it is a string
what're ya, code academy?

  No.13486

mips assembly

    .data

str1: .asciiz "What is your name ? "
str2: .asciiz "Greetings, "

.text
.globl main

main:

li $v0, 4
la $a0, str1
syscall

li $v0, 8
syscall

move $t0, $a0

li $v0, 4
la $a0, str2
syscall

move $a0, $t0

li $v0, 4
syscall

jr $ra

  No.13506

>>8494
Python 3. 48 characters.
print("Greetings,", input("What's your name? "))

  No.13508

Since C-s java only returns javascript, here is a the write-once, run anywhere happy codemonkey version:

emacs ManyGreets.java // or C-x C-f ManyGreets.java <Ret> if you are already in emacs

import java.util.Scanner;

public class ManyGreets {
public static void main(String[] args) {

Scanner kb = new Scanner(System.in);
System.out.print("What is your name? ");
String namae = kb.nextLine();
for (int i=0; i<100; i++)
System.out.println("Greetings, " + namae + ".");

kb.close();
}
}

C-x C-s
C-x C-c // or M-x ansi-term <Ret><Ret>

javac ManyGreets.java
java ManyGreets

  No.13737

Kinda surprised that nobody tried this in x86.

section .data

msg1: db 'What is your name?',0xa

msg2: db 'Greetings, '
len2: equ $-msg2

section .text

global _start
_start: mov rdx,msg2-msg1
mov rsi,msg1
mov rdi,1
mov rax,rdi
syscall

mov rsi,msg2+len2
dec rdi
xor rax,rax
syscall
xor rcx,rcx
or rcx,len2
add rcx,rax
mov word [msg2+rcx-1],0x0a2e
inc rcx

mov rdx,rcx
mov rsi,msg2
inc rdi
mov rax,rdi
syscall

xor rdi,rdi
mov rax,0x3c
syscall

  No.13740

First attempt with Pyth, it could probably be shorter. 44 chars.
p"What is your name? "=kwp"Greetings, "pk"."

  No.13747

Here's my attempt in COBOL:
DISPLAY "What's your name?"
ACCEPT name
DISPLAY "Greetings, " name "!"

  No.13770

>>9996
Nice.

  No.13779

Am I really the first?
main=putStr"What is your name? ">>getLine>>=putStrLn.("Greetings, "++).(++".")

  No.13780

>>13779
Nah, Haskell was one of the first replys.

>>8527

  No.13794

>>13780
>Nah, Haskell was one of the first replys.
Identical code too, wow. I didn't even see that.

  No.13821

>>10216
Ya think so?
And where's my D lang niggas?

  No.15658

>>9996
Here's a slightly shorter version at 41 chars: 'What is your name? '⋄'Greetings, ',⍞,'.'

  No.16162

python in terminal
'Greetings, '+input('What is your name?')+'.'

  No.16197

saturn
main:
str name
out stdout, 'What is your name? '
get name, stdin
out stdout, 'Greetings, '
out stdout, name

  No.16786

Brainfuck, 272 Bytes:
++++[>++++<-]>[>+++++>++++>++++++>+++++++>++>+++>+[<]>-]>+++++++.>>+++
+++++.-------.>++++.>.<<++++++++.>-.>.<++++++.----------.++++++.---.>.
<----.<--------.>-.<++++.<-.>>>.>>------.>,[>,]<[<]>>++++++++.>>+++++.
<..>++.<++++.>------.<--.>+++++.[-]>>----.<.>>>[.>]<[<]>>++.>.

  No.16814

>>8491

bash 45 char
read -p "what is your name" x; echo Hello, $x

  No.16826

>>10009
>>10030

You can of course print the name of the script itself with $0. Here is a more complete example:

read -p "${0%.*} "; echo Greetings, $REPLY

Simpler still if you don't give the script a .sh extension.

  No.16835

>>16826
$REPLY is the standard variable for read?

  No.16836

>>10030
>>10009
echo Greetings, ${@}.
now it accepts spaces :)

  No.16902

>>10231
Why did it take so many responses for someone to post Scheme?

Shorter:
(display"What is your name? ")(format #t"Greetings, ~a."(read-line))

Assumes a sane standard environment. 68 chars.

  No.16905

>>16902
Scheme doesn't golf well (Lisps in general but Scheme especially), and Schemers tend to dislike golfing their code. We see verbosity as a good thing, because it is uniform like Lisp's syntax. No form of abbreviation will ever suffice in all situations, so choosing the least common denominator (just writing it out) means that we're able to easily guess function names we may have only looked up once.

  No.16909

>>16905
Well yeah, still the OP had CL and Elisp so it irritated me that near to nobody posted Scheme, i.e. The Best Lisp.

  No.16910

>>16909
Yeah, that's fair
>The Best Lisp
You're a Scheme weenie but I agree (and I'm one too).

  No.16911

>>16910

Do you have an opinion on R7RS or recent SRFIs?

I wrote SRFI 126 because 125 was all WTF. But writing one drained all my power already. J. Cowan also wants to make an SRFI of my bytestructures lib tho.

  No.16912

>>16911
I should probably ask these things in the Lisp general but w/e.

  No.16914

>>16911
You've worked on the SRFIs? That's awesome.
I like R7RS generally. To me it's like R5RS with libraries and record types, and some other nice extensions (stuff people had to painfully work around when designing R5RS-compatible libraries). I like writing R7RS compatible language extensions e.g. pattern matchers, and my practice using CPS syntax-rules comes in handy still.

I'm still not sure how to feel about call/cc and would honestly like to see it gone from the language entirely but I guess people are tired of that argument. Over time people have lost confidence in its ability to work as goto/return/error handling and R7RS-small even has an error handling system.

I never used R6RS too much-- I'm not sure how to feel about syntax-case, and when I started programming (only a few years ago) it seemed like Racket was a better, or perhaps more simple language to learn and use.

I haven't kept up with the SRFIs too much lately to be honest. I used to read them more when I was learning Scheme. What happened to R7RS-large? Last I checked it had been a long time since any work was done on it but I haven't really looked at the mailing list in awhile.

  No.16918

>>16914
Call/cc is definitely the wrong thing. It will stay because of backwards compatibility, but hopefully R7RS-large will get delimited continuations which have none of the problems with call/cc.

I find syntax-case pretty awesome after having grokked it and used it in a project (bytestructures' optional macro API). I wish R7RS didn't set back on so many things from R6RS.

R7RS-large is being developed mainly in the form of SRFIs, which will then become part of R7RS-large. Most of the SRFIs from 111 upwards were written with intention of becoming R7RS-large libraries.

A week or so ago J. Cowan announced that we're approaching the end of the first stage of R7RS-large, which he calls the Red Edition / Data Structures. There's some voting and final discussion going on in the scheme-reports-wg2 Google group...

  No.16919

>>16918
Thanks for the updates on R7RS-large. I should read the SRFIs carefully to get an idea for the new language. With the community so divided on R6RS it was to be expected that something like R7RS-small was to be created. Some very prominent members of the community outright hate it.

I understand syntax-case, it just feels like the wrong thing for something like Scheme to implement. The point of Scheme is to only include what's necessary, and the large baggage of R6RS's macro system is really what I have a problem with. I admit that it does match the rest of the described language, but in general that language feels excessive and non-Schemey to me.

In general the pattern language of syntax-rules should be generalized somehow. I prefer the syntax preserving, yet very simplistic ir-macro-transformer and er-macro-transformer, which use the underlying language to generate code*. syntax-rules could be defined in terms of them easily. It feels like syntax-rules' pattern language should at least be present elsewhere in the language, rather than be a strange alternative to quasiquotation that only gets used in the macro system.

* I've come around to believe that this is a necessary part of Lisp that Scheme is strangely missing. With syntax-rule's pattern language, and a lack of the Scheme runtime being available at compile time, this becomes a very small part of Scheme writing. I like the pattern language, but I think it should be definable in a more simple macro definer.

  No.16920

>>16919
I meant to add at the end:
Though you may not agree with my view points and think that syntax-case is a natural thing to standardize in Scheme, that's fine, I just hope that you understand my viewpoint. It feels to me like there's a version of Scheme which has a very small number of true core forms that is able to describe itself, both as an interpreter and otherwise. I like that there aren't sockets or other I/O things as part of the core language, and I like its intense focus on purity and recursion. It seems to me like this language is the goal of R7RS-small, and perhaps earlier Schemes.

  No.16935

>>8491
Racket Lisp, 52 chars.
(~a"What is your name?")(~a"Greetings, "(read-line))

Racket provides a convenient short-hand for function formatting, you can just use the options like ~a, ~v, etc. as function calls!

  No.16936

>>16919
>>16920
I kind of understand your viewpoint. Exposing the s-expressions making up the code to the procedural macro system seems like a no-brainer, upon which higher abstractions would be built.

I would contend though that it's a mistaken perspective. I don't expect to absolutely change your mind, but let me try. I'll argue my position from both a theoretical and practical side. Starting with the theory...

While Scheme code is made up of s-expressions at the lowest level, these sexprs gain additional meaning within the semantics of Scheme. As we know, every sexpr is evaluated in a given environment. For instance in R7RS, this environment is determined either by the series of imports at the start of a top-level R7RS program, the import declarations of a library definition, or the explicit environment object passed to the eval procedure. Thus, every sexpr that makes up Scheme code to be evaluated also has a context, an evaluation environment, attached to it. Therefore, a raw sexpr is not the correct reification of code when passed to or returned from a metaprogramming system such as procedural macros. Under syntax-case, the reified syntax objects correctly consist of a sexpr plus its context information. The ones passed to the macro system have the context already bundled, and the macro system can create further such syntax objects with appropriate context bundled to them via 'syntax', 'quasisyntax', and 'datum->syntax'. Raw sexprs can be extracted from syntax objects via 'syntax->datum'

Now, one could say that an equally valid reification is to pass the sexprs and context as separate objects. Semantically, I suppose this is equivalent. It is indeed what Syntactic Closures (SC), Reverse Syntactic Closures (RSC), and Explicit Renaming (ER) macro systems do in different ways, though they also all do something special/implicit when a raw sexpr is returned from a macro procedure:

- The SC system passes procedural macros a sexpr and an env object corresponding to the environment from which the macro is called (the caller environment). The programmer uses make-syntactic-closure to bundle the caller environment to an identifier; otherwise the identifier will be bundled with the environment in which the macro was defined (the definition environment) when it's returned from the macro procedure.

- The RSC system passes procedural macros a sexpr and the definition environment. The programmer uses make-syntactic-closure to bundle the definition environment to an identifier; otherwise the identifier will be bundled with the caller environment when it's returned from the macro procedure, though this is pretty much the same thing as what happens with 'define-macro', which is that the identifier is simply evaluated at the macro call site as if it appeared there normally. Therefore you could say RSC macros are "unhygienic by default".

- The ER system passes procedural macros a "rename" procedure which bundles the definition environment to an identifier when the procedure is called on it. Other identifiers are implicitly bundled with the caller environment upon return. Essentially, ER seems to be a thin wrapper around RSC.

This might be subjective, but I would say these are lazy and clumsy abstractions. SC and RSC are pretty low-level; why burden the programmer with the task of manually bundling identifiers with environments? SC at least bundles the definition environment to bare identifiers implicitly on return, but that in turn is clumsy and limits some usages I will touch upon later.

  No.16937

As for the IR system, it's the least bad: from the sexpr (tree) it passes to procedural macros, all the leaves are already bundled with the calling environment, and bare identifiers are bundled with the definition environment upon return. This is a fairly fine abstraction, but has the clumsiness of implicit bundling, which I will now explain.

The problem with implicit bundling of the definition environment is, it doesn't let you compose syntax objects stemming from a variety of environments. I learned the usefulness of this through experience, making good use of syntax-case's capabilities in my Bytestructures library to offer an optional macro API to users who need maximum performance; via this, one can offload all offset calculation of structs to compile-time, essentially giving you something like C's type system for Scheme (it's indeed for FFI purposes, among more). This works thanks to the possibility of every bytestructure descriptor object (essentially a "type" object) being able to return its own partial syntax object --bundled to its own definition environment-- to a larger subsystem at compile time, that composes these syntax objects together to create the final piece of code that references bindings from all across the different modules in which different descriptors are defined.

Note that while the bundling of a definition environment to an identifier is *explicit* under syntax-case, it's still *automatic*. You don't need to call a procedure on every single identifier you want to bundle; rather you can use 'syntax' or 'quasisyntax' to have a whole sexpr bundled to the environment in which it appears.

The only annoyance with syntax-case is that bundling doesn't necessarily happen at the level of identifiers. When you bundle a whole expression like (cons foo bar) with an environment, you'll get a single syntax object containing that list of symbols as its payload, rather than a list of three syntax objects that are individually bundled with the given environment. The 'syntax-case' special form lets one destructure such syntax objects easily though, transparently working both with syntax objects containing lists, and lists containing syntax objects.

External resources on SC, RSC, ER, and IR systems:
http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Macros.html
https://wiki.call-cc.org/man/4/Macros
https://wiki.call-cc.org/explicit-renaming-macros

Bytestructures:
https://github.com/TaylanUB/scheme-bytestructures

  No.16938

>>16936
>>16937
I should have posted this in the Lisp General. Anyway, I'll save this somewhere for the future.

  No.17085

>No one tried with Windows CLI scripting yet
I cut it down more by few chars, but it gives cleaner output with echo off set first.
55 characters long.


echo off
set /p a=What is your name?
echo Greetings %a%

  No.17105

>>10638
Why use fmt? There are built-ins.

  No.17108

lol

Lua:

input = " "
print("What is your name?")
input = io.read()
print("Greetings " .. input)

  No.17111

>>16814
with you not cheating, that's 52
read -p "What is your name? " x; echo Greetings, $x

also, zsh best girl (48)

read 'n?What is your name? ';echo Greetings, $n

  No.17444

>>13508
Why not use M-x compile?

I personally prefer the elisp shell for quick things like checking a small program works, since it doesn't steal C-x away from you.

  No.17524

>>11156
Or:

puts "What is your name? "; puts "Greetings #{gets.chomp}"

  No.17526

>>11148
print("greetings",input("what is your name?"))
47

  No.19242

>>11154
>c++
>let's link readline lolollolollo
>not just std::getline (#include iostream)
>not just fgets (stdio.h)
2/10

  No.19245

>>19242
Are you aware that you're replying to a year-old post?

  No.19273

>>19245
king necrobump.

  No.19283

Ada, cause verbosity and readable source code is cool.

with Ada.Text_IO; use Ada.Text_IO;

procedure Greeting is
Name : String (1..20);
N : Positive;
begin
Put ("What is your name? ");
Get_Line (Name, N);
Put_Line ("Greetings, " & Name (1 .. N) & ".");
end Greeting;

  No.19367

>>19245
>neurosuggesting lainchan threads die before falling off the board

  No.21534

>>8494
You shouldn't use the %s, %d stuff.
{} and the 'format' method is the new standard.

print('Greetings, {}.'.format(input('What is your name? ')))

  No.21535

>>21534
No, fstrings are the new standard. Get on the 3.6 train, grandpa.

  No.21541

Why no-one has done in C? You are lazy bastards, I tell you this.

  No.21543

>>21541
OK, here's my variable-width overflow-proof solution:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* read_line ()
{
size_t len = 0, cap = 4;
char* buf = NULL;
do {
buf = realloc(buf, cap *= 2);
fgets(buf + len, cap - len, stdin);
len = strlen(buf);
} while (buf[len-1] != '\n');
buf[len - 1] = '\0';
return buf;
}
int main (void)
{
printf("What is your name? ");
fflush(stdout);
printf("Greetings, %s.\n", read_line());
return 0;
}

  No.21545

>>13102
>>17108

You don't need to store the input and you can kill some whitespace:
print"What is your name?"print("Greetings, "..io.read())
56.

  No.21550

>>21541
>>21543
Here is my golfed version, I'd like to see somebody else try to make one shorter while still allowing "boundless" input
void P(void**f,void**n){
char c=getchar();
if(c==10){
printf("Greetings, ");
for(;f;f=f[1])putchar(*(char*)*f);
puts(".");
}else{
void*l[2]={&c,0};
if(n)*n=l;
P(f?:l,l+1);
}
}
main(void){
printf("What is your name? ");P(0,0);
}

  No.21555

vhdl, make sure you name is 20 chars long

LIBRARY std;
USE std.TEXTIO.all;


entity greeter is
end entity greeter;


architecture greet of greeter is
begin
process
variable line_in, line_out : line;
variable name : string(20 downto 0);
begin
write(line_out, string'("What is your name?"));
writeline(OUTPUT, line_out);

readline(INPUT, line_in);
read(line_in, name);

write(line_out, string'("Greetings, ") & name);
writeline(OUTPUT, line_out);
end process;
end architecture greet;

  No.21557

<?php
$stdin = fopen('php://stdin', 'r');
do {
echo 'What is your name? ';
$input = trim(fgets($stdin));
} while($input === '');
fclose($stdin);
echo "Greetings, $input.\n";

  No.21559

223 characters is the best I could do in Java. How much does "number of characters it takes to do a thing" say about a language?

import java.util.Scanner;

public class Greetings {
public static void main(String[] args) {
System.out.print("What is your name? ");
System.out.println("Greetings, " + (new Scanner(System.in)).nextLine());
}
}

  No.21564

Powershell 50 characters

read-host "What is your name?"|%{"Greetings, $_."}

  No.21565

Ah just read some examples here.
Powershell down to 47 characters

"Greetings, $(read-host "What is your name?")."

  No.21679

You can print out with just "p" to make a little shorter. Down to 40
p 'Whats your name';p "Greetings, "+gets

  No.21682

>>21559
Not much besides differing syntax.

  No.21701

>>21679
`p` prints the internal representation though, which includes the double quotes.

  No.21713

gnu guile
(use-modules(ice-9 readline)(ice-9 format))(format #t"Hello, ~a.\newline"(readline"What is your name? "))

  No.21726

>>21713
smaller gnu guile
still 95 chars :c
(use-modules(ice-9 readline)(string-append"Hello, "(readline"What is your name? ")".\newline")

  No.21736

llvm... what I could get working at least
@ask = private unnamed_addr constant [19 x i8] c"What is your name? ", align 1
@greet = private unnamed_addr constant [11 x i8] c"Greetings, ", align 1
define i32 @main() #0
{
%buffer = alloca [20 x i8], align 16
%ask = getelementptr inbounds [19 x i8], [19 x i8]* @ask, i32 0, i32 0
%greet = getelementptr inbounds [11 x i8], [11 x i8]* @greet, i32 0, i32 0
%input = getelementptr inbounds [20 x i8], [20 x i8]* %buffer, i32 0, i32 0
call void @llvm.memset.p0i8.i64(i8* %input, i8 0, i64 20, i32 16, i1 false)
call i64 @write(i32 1, i8* %ask, i64 19)
call i64 @read(i32 0, i8* %input, i64 20)
call i64 @write(i32 1, i8* %greet, i64 11)
call i64 @write(i32 1, i8* %input, i64 20)
ret i32 0
}
declare void @llvm.memset.p0i8.i64(i8*, i8, i64, i32, i1)
declare i64 @read(i32, i8*, i64) #1
declare i64 @write(i32, i8*, i64) #1

  No.21747

PHP solution for non-CLI (78 chars):
  echo (!empty($_GET['n']) ? 'Greetings, ' . $_GET['n'] : 'What is your name?'); 

  No.21748

File: 1485976981003.png (64.08 KB, 200x160, How-did-this-happen.jpg)

i am about to host a site . the site has 20mb of data. the rest will be added by the users.
by estimate i think it will have data of about 500gb.
i want to set up the server in my own basement or backyard. can anyone recommend me a good server with atleast 5gb/s , more than 8gb of ram and hardisk of about 500gb-1TB .
from where should i register the domain. considering the fact that users outside my country will face speed issues because the site will have only 1 server that is in my home...should i register for cloudflare, and how much is all thay gonna cost me....
if you have books on this topic pls provide and message you opinion.
i couldn't afford college so learning on my own...help is necessary. . .

  No.21767

>>21726
,use(ice-9 readline)(string-append"Greetings, "(readline"What is your name? ")".")

down to 82 chars

  No.22464

>>21535
fstrings are byte code optimized. For runtime it's better to use string formatting.