Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Cのプリプロセッサ on Go言語
package main
import (
#define map(TYPE_S, TYPE_F, SOURCE, FUNC)\
func (f func(TYPE_S) TYPE_F) []TYPE_F {\
r := make ([]TYPE_F, len(SOURCE));\
for i, e := range SOURCE {\
r[i] = f(e)\
return r;\
func square(x int) int {
return x * x
func main() {
numbers := []int{1,2,3,4,5}
result := map(int, int, numbers, square)
fizzbuzz := map(int, string, numbers, func (x int) string {
switch x % 15 {
case 0: return "FizzBuzz"
case 3,6,9,12: return "Fizz"
case 5,10: return "Buzz"
default: return strconv.Itoa(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.