ITT we appreciate aesthetically pleasing programming languages. Whatever you find beautiful goes.parseApp :: [String] -> (Ast, [String])
parseApp [] = error "No tokens to parse at parseApp"
parseApp (x:xs) = (App (Name x) [a, c ] , d)
where (a,b) = parseExpr xs;
(c,d) = parseExpr b
pic unrelated
>>51805437HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!!!1!"
KTHXBYE
>>51805437oop{
match self.soc.read() {
Ok( (op_code, data) ) => {
use wss::util::OpCode::*;
match op_code {
Continuation | Text | Binary => self.buf.append(&mut data.clone()),
Close => {
self.kick("disconnected.".to_string());
return None;
},
Ping => {
let _ = self.soc.write(Pong, &mut vec![]); // ignore the result
},
Pong => continue,
}
},
Err(ReadError::EAGAIN) => break, // nothing to read
Err(err) => {
self.kick(format!("connection error: {}", err));
return None;
},
}
}
Also I love how nice and compact things you can do macros, even if they don't look so clear by themselves.macro_rules! create_packets {
(
$(
$name:ident($packet_id:expr => $( $dataname:ident : $datatype:ty ),* );
)*
) => {
impl Message {
$(
pub fn $name( $( $dataname:&$datatype ),* ) -> Message {
let mut msg = Message{
id: $packet_id,
len: 0,
pos: 0,
data: Vec::new(),
};
$(
msg.data.append( &mut $dataname.to_message() );
)*
msg.len = msg.data.len();
msg
}
)*
}
}
}
create_packets!{
player_joined(1 => name:String, player_id:usize, secret:String, color:i32, team:i32);
player_leaved(2 => player_id:usize, reason:String);
synchronize_dots(3 => uid:Uid, dots_list:Vec<Option<Dot>>);
update_foods(6 => food_table:Vec<u8>);
player_list(9 => player_list:Vec<Option<Player>>);
ping(12 => msg:String);
}
>>51805437package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
>>51805437char *strcpy(char *d, const char* s){
char *r = d;
while(*d++=*s++);
return r;
}
public function execute ( $action, $args, $callbackContext ) {
echo args[str_len($action)%2];
return;
}
>>51805437(1 until 100).map ( i => (i % 3, i % 5) match {
case (0, 0) => "FizzBuzz!"
case (0, _) => "Fizz"
case (_, 0) => "Buzz"
case _ => i
}).foreach (println)
I surprisingly have started to really like typescript, example with angular typescriptexport class TechVidsListCtrl {
private $scope: Extensions.ITechVidsScope;
private $routeParams: Extensions.ITechVidsRouteParams;
private dataSvc: TechVidsDataSvc;
private init(): void {
var self = this;
//Fetching all videos if id is not found in route path
if (self.$routeParams.id !== undefined) {
self.dataSvc.getVideosByCategory(parseInt(this.$routeParams.id))
.then(function (data) {
self.$scope.videos = data;
});
}
//Fetching videos specific to category if id is found in route path
else {
self.dataSvc.getAllVideos().
then(function (data) {
self.$scope.videos = data;
});
}
}
constructor($scope: Extensions.ITechVidsScope,
$routeParams: Extensions.ITechVidsRouteParams,
dataSvc: TechVidsDataSvc) {
var self = this;
self.$scope = $scope;
self.$routeParams = $routeParams;
self.dataSvc = dataSvc;
self.$scope.upRate = function (id: number, rating: number) {
self.dataSvc.setRating(id, rating + 1)
.then(function () {
self.init();
});
};
self.$scope.downRate = function (id: number, rating: number) {
self.dataSvc.setRating(id, rating - 1)
.then(function () {
self.init();
});
};
self.init();
}
}
TechVidsListCtrl.$inject = ['$scope', '$routeParams', 'techVidsDataSvc'];
>>51806314
>not writing your strcpy in assembly
>>51806518
This is how asm code gcc -S -masm=intel -O3 looks like:strcpy:
.LFB0:
.cfi_startproc
mov rax, rdi # dest, dest
mov rdx, rdi # dest, dest
.p2align 4,,10
.p2align 3
.L2:
add rsi, 1 # src,
movzx ecx, BYTE PTR [rsi-1] # D.1856, MEM[base: src_8, offset: -1B]
add rdx, 1 # dest,
test cl, cl # D.1856
mov BYTE PTR [rdx-1], cl # MEM[base: dest_7, offset: -1B], D.1856
jne .L2 #,
rep ret
.cfi_endproc
I'm pretty sure it's not possible to optimize it more. Also you would lose portability and stuff.
#lang racket
(require file/unzip)
(module+ main
(define zip-files (filter (lambda (path)
(string-suffix? (path->string path) ".zip"))
(directory-list)))
(for ([file-name zip-files])
(unzip (build-path (current-directory)
file-name)
(make-filesystem-entry-reader
#:dest (path-replace-suffix (build-path (current-directory)
file-name)
"")))))