Tag: language

Python AST: Evaluate an Expression

Do you want to convert a string of Python expression to Python object? Use ast $ cat myast.py import ast exDict = ‘{“name”: “1”}’ x = ast.literal_eval(exDict) print(x) $ python myast.py {‘name’: ‘1’} Another Example >>> import ast >>> x = u'[ “A”,”B”,”C” , ” D”]’ >>> x […]

Understanding Ruby Symbols

Ruby is an interpreted language. It is dynamically typed and uses a new memory for a variable. A variable has a name and a value. Symbols are an optimized variable that holds single instance of memory. It is good for variables that assume the same values across the […]

Golang: Switch-case does not fall through!

Unlike C/C++ switch-case statements, Golang switch case does not fall through. package main import ( “fmt” ) func main() { fmt.Print(“Go runs on “) os := “darwin” switch os { case “darwin”: case “linux”: fmt.Println(“Linux.”) default: // freebsd, openbsd, // plan9, windows… fmt.Printf(“%s.\n”, os) } } The above […]

Forward declaration of a structure in C

What do you think of following code? /* * decl.h */ struct junk { int a; }; ———————————————- /* * fwd.c * We have not included the header file decl.h. */ #include struct junk; int main() { struct junk *ptr; printf(“%d”, ptr->a); } You will get compilation error […]