[ 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)


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.


This is even more basic than FizzBuzz though.

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


Javascript (54 chars):

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

Perl (57 chars):

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

It's on par with Hello World.


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


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


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


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.


echo Greetings, ${1}.

save as "What is your name?.sh"




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.


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


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.


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


#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;


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


python is sexy as fuarrrk


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

.global _start

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

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

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

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

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

MOV r7, #1

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


Well, soykaf .
This should be better.

.global _start

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

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

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

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

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

MOV r7, #1

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


C++ 126 chars

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



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



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


Go (143 chars):

package main

import "fmt"

var n string

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

>Your request looks automated; Post discarded.

Piece of soykaf imageboard engine.


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.


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


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?


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


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.


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

./phon hello



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

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


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



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



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

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


puts "What is your name?"
puts "Greetings, " + name.to_s

70 chars


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()?


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



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


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.



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


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


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


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.


Ah yes, I was being dumb there.


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



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


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



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


int a[99]; brings it down to 80


Doesn't this allow for a buffer overflow?


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.


Didn't know you could do that. Thanks PyWizard


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


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
(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
# 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


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


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


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.


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


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



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



Nope, I missed the period.

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



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


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


It doesn't follow the specs though quads man.


>doesn't work if your input has spaces


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


mips assembly


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

.globl main


li $v0, 4
la $a0, str1

li $v0, 8

move $t0, $a0

li $v0, 4
la $a0, str2

move $a0, $t0

li $v0, 4

jr $ra


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


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 + ".");


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

javac ManyGreets.java
java ManyGreets


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

mov rsi,msg2+len2
dec rdi
xor rax,rax
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

xor rdi,rdi
mov rax,0x3c


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


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




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


Nah, Haskell was one of the first replys.



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


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


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


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


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


Brainfuck, 272 Bytes:



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



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.


$REPLY is the standard variable for read?


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


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

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

Assumes a sane standard environment. 68 chars.


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.


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


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



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.


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


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.


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


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.


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.


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!


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.


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:



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


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


Why use fmt? There are built-ins.




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


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


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.



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


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


>let's link readline lolollolollo
>not just std::getline (#include iostream)
>not just fgets (stdio.h)


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


king necrobump.


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;
Put ("What is your name? ");
Get_Line (Name, N);
Put_Line ("Greetings, " & Name (1 .. N) & ".");
end Greeting;


>neurosuggesting lainchan threads die before falling off the board


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, fstrings are the new standard. Get on the 3.6 train, grandpa.


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


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? ");
printf("Greetings, %s.\n", read_line());
return 0;



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


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();
printf("Greetings, ");
printf("What is your name? ");P(0,0);


vhdl, make sure you name is 20 chars long

USE std.TEXTIO.all;

entity greeter is
end entity greeter;

architecture greet of greeter is
variable line_in, line_out : line;
variable name : string(20 downto 0);
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;


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


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());


Powershell 50 characters

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


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

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


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


Not much besides differing syntax.


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


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


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


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


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


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


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

down to 82 chars


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