[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
ITT we appreciate aesthetically pleasing programming languages.
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 11
Thread images: 1
File: 1415974298334.jpg (1 MB, 1920x1440) Image search: [Google]
1415974298334.jpg
1 MB, 1920x1440
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
>>
>>51805437
HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!!!1!"
KTHXBYE
>>
>>51805437
oop{
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);
}
>>
>>51805437
package main

import "fmt"

func main() {
fmt.Println("Hello, world!")
}
>>
>>51805437
char *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 typescript

export 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)
"")))))
Thread replies: 11
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.