Map operators
Operators on hash maps.
Every program can use these operators. No import is necessary.
| Operator | Arguments | Gives |
|---|---|---|
def |
varname: [K:T] | void |
for |
hash: [string:T], itemName: string, repeat_block: block | void |
for |
hash: [string:T], item: T, itemName: string, repeat_block: block | void |
get |
map: [K:boolean], key: K | <optional>boolean |
get |
map: [K:double], key: K | <optional>double |
get |
map: [K:int], key: K | <optional>int |
get |
map: [K:T], key: K | <optional>T |
has |
map: [K:T], key: K | boolean |
keys |
map: [string:T] | [string] |
map_clear |
map: [K:T] | void |
set |
map: [K:T], key: K, value: T | void |
Target support marks
- Own template
- Default template
- No template
The operator works for a target with an own template and for a target with the default template. The default template is the * entry of the definition: it writes the same code for every target that has no template of its own. A target with no template writes no code, and a program that uses the operator does not compile for that target.
def
(def varname) → void
def(varname: [K:T])Target support
- JavaScript: default template
- TypeScript: default template
- Go: default template
- Rust: default template
- Python: default template
- Java: default template
- Kotlin: default template
- Dart: default template
- Swift: default template
- C#: default template
- C++: default template
- PHP: default template
- Scala: default template
Definition: compiler/Lang.rgr, line 4367
for
(for hash itemName repeat_block) → void
for(hash: [string:T], itemName: string, repeat_block: block)Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: own template
- Swift: own template
- C#: own template
- C++: own template
- PHP: own template
- Scala: own template
Definition: compiler/Lang.rgr, line 5913
for
(for hash item itemName repeat_block) → void
for(hash: [string:T], item: T, itemName: string, repeat_block: block)Walking a hash map used to be an es6 only operator: the two `for` shapes below carried one template each, so every other target answered `Could not match argument types for for` and a program that iterated a map compiled on JavaScript alone.
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: own template
- Swift: own template
- C#: own template
- C++: own template
- PHP: own template
- Scala: own template
Definition: compiler/Lang.rgr, line 5886
get
(get map key) → <optional>boolean
get(map: [K:boolean], key: K)`bool` and `null` have no common type, so the generic overload's conditional does not compile for a map of booleans -- the int and the double overloads above carry a cast for exactly this reason. Only C# has an entry here, so every other target keeps reaching the generic overload below.
Target support
- JavaScript: no template
- TypeScript: no template
- Go: no template
- Rust: own template
- Python: no template
- Java: no template
- Kotlin: no template
- Dart: no template
- Swift: no template
- C#: own template
- C++: no template
- PHP: no template
- Scala: no template
Definition: compiler/Lang.rgr, line 9168
get
(get map key) → <optional>double
get(map: [K:double], key: K)Target support
- JavaScript: own template
- TypeScript: own template
- Go: default template
- Rust: own template
- Python: own template
- Java: default template
- Kotlin: default template
- Dart: default template
- Swift: default template
- C#: own template
- C++: own template
- PHP: default template
- Scala: default template
Definition: compiler/Lang.rgr, line 9107
get
(get map key) → <optional>int
get(map: [K:int], key: K)Target support
- JavaScript: no template
- TypeScript: no template
- Go: no template
- Rust: own template
- Python: own template
- Java: no template
- Kotlin: no template
- Dart: no template
- Swift: no template
- C#: own template
- C++: own template
- PHP: no template
- Scala: no template
Write and read a hash map
class Main { sfn main:void () { def ages:[string:int] set ages "ada" 36 set ages "alan" 41 def age (?? (get ages "ada") 0) print ("ada " + age) if (has ages "alan") { print "alan is in the map" } }}let ages = {};ages["ada"] = 36;ages["alan"] = 41;const age = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0);console.log("ada " + age);if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map");}The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { let ages = {}; ages["ada"] = 36; ages["alan"] = 41; const age = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0); console.log("ada " + age); if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map"); }}__js_main();let ages : {[key:string]:number} | undefined = {};ages["ada"] = 36;ages["alan"] = 41;const age : number = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0);console.log("ada " + age);if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map");}The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { let ages : {[key:string]:number} | undefined = {}; ages["ada"] = 36; ages["alan"] = 41; const age : number = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0); console.log("ada " + age); if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map"); }}__js_main();var ages map[string]int64 = make(map[string]int64);ages["ada"] = int64(36);ages["alan"] = int64(41);var age int64= (func() int64 { if r_get_string_int64(ages, "ada").has_value { return r_get_string_int64(ages, "ada").value.(int64) } else { return int64(0)} }());fmt.Println( strings.Join([]string{ "ada ",strconv.FormatInt(age, 10) }, "") )if r_has_key_string_int64(ages, "alan") { fmt.Println( "alan is in the map" )}The complete file
package mainimport ( "strings" "strconv" "fmt")
type GoNullable struct { value interface{} has_value bool}
func r_get_string_int64( a map[string]int64, key string ) *GoNullable { res := new(GoNullable) v, ok := a[key] if ok { res.has_value = true res.value = v return res } res.has_value = false return res}func r_has_key_string_int64( a map[string]int64, key string ) bool { _, ok := a[key] return ok
}type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var ages map[string]int64 = make(map[string]int64); ages["ada"] = int64(36); ages["alan"] = int64(41); var age int64= (func() int64 { if r_get_string_int64(ages, "ada").has_value { return r_get_string_int64(ages, "ada").value.(int64) } else { return int64(0)} }()); fmt.Println( strings.Join([]string{ "ada ",strconv.FormatInt(age, 10) }, "") ) if r_has_key_string_int64(ages, "alan") { fmt.Println( "alan is in the map" ) }}The compiler does not write Rust code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?The compiler does not write Python code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?RgArgs.args = args;HashMap<String,Integer> ages = new HashMap<String,Integer>();ages.put("ada", 36);ages.put("alan", 41);final Integer age = (ages.get("ada") != null ) ? ages.get("ada") : 0;System.out.println(String.valueOf( "ada " + age ) );if ( ages.containsKey("alan") ) { System.out.println(String.valueOf( "alan is in the map" ) );}The complete file
import java.util.*;import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; HashMap<String,Integer> ages = new HashMap<String,Integer>(); ages.put("ada", 36); ages.put("alan", 41); final Integer age = (ages.get("ada") != null ) ? ages.get("ada") : 0; System.out.println(String.valueOf( "ada " + age ) ); if ( ages.containsKey("alan") ) { System.out.println(String.valueOf( "alan is in the map" ) ); } }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsvar ages : MutableMap<String,Int> = hashMapOf();ages.set("ada", 36)ages.set("alan", 41)val age : Int = (ages["ada"] ?: 0);println( "ada " + (age).toString() )if ( ages.containsKey("alan") ) { println( "alan is in the map" )}The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args var ages : MutableMap<String,Int> = hashMapOf(); ages.set("ada", 36) ages.set("alan", 41) val age : Int = (ages["ada"] ?: 0); println( "ada " + (age).toString() ) if ( ages.containsKey("alan") ) { println( "alan is in the map" ) }}__g_args = args;Map<String, int> ages = {};ages["ada"] = 36;ages["alan"] = 41;int age = (ages["ada"] ?? 0);print( "ada " + (age).toString() );if ( ages.containsKey("alan") ) { print( "alan is in the map" );}The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; Map<String, int> ages = {}; ages["ada"] = 36; ages["alan"] = 41; int age = (ages["ada"] ?? 0); print( "ada " + (age).toString() ); if ( ages.containsKey("alan") ) { print( "alan is in the map" ); }}var ages : [String:Int] = [String:Int]()ages["ada"] = 36;ages["alan"] = 41;let age : Int = (ages["ada"] ?? 0)print("ada " + String(age))if ( ages["alan"] != nil ) { print("alan is in the map")}The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { var ages : [String:Int] = [String:Int]() ages["ada"] = 36; ages["alan"] = 41; let age : Int = (ages["ada"] ?? 0) print("ada " + String(age)) if ( ages["alan"] != nil ) { print("alan is in the map") }}__main__swift()Dictionary<String,int> ages = new Dictionary<String,int>();ages["ada"] = 36;ages["alan"] = 41;int age = ((ages.ContainsKey("ada") ? (int?)ages["ada"] : null) ?? 0);Console.WriteLine("ada " + age);if ( ages.ContainsKey("alan") ) { Console.WriteLine("alan is in the map");}The complete file
using System;using System.Collections;using System.Collections.Generic;class Main { static void Main( string [] args ) { Dictionary<String,int> ages = new Dictionary<String,int>(); ages["ada"] = 36; ages["alan"] = 41; int age = ((ages.ContainsKey("ada") ? (int?)ages["ada"] : null) ?? 0); Console.WriteLine("ada " + age); if ( ages.ContainsKey("alan") ) { Console.WriteLine("alan is in the map"); } }}The compiler does not write C++ code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?$ages = array();$ages["ada"] = 36;$ages["alan"] = 41;$age = ($ages["ada"] ?? 0);echo( "ada " . $age . "\n");if ( array_key_exists("alan" , $ages ) ) { echo( "alan is in the map" . "\n");}The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$ages = array();$ages["ada"] = 36;$ages["alan"] = 41;$age = ($ages["ada"] ?? 0);echo( "ada " . $age . "\n");if ( array_key_exists("alan" , $ages ) ) { echo( "alan is in the map" . "\n");}var ages : collection.mutable.HashMap[String, Int] = new collection.mutable.HashMap()ages.put("ada", 36)ages.put("alan", 41)val age : Int = (ages.get("ada")).getOrElse(0)println( "ada " + age )if ( ages.contains("alan") ) { println( "alan is in the map" )}The complete file
import scala.collection.mutablecase class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { var ages : collection.mutable.HashMap[String, Int] = new collection.mutable.HashMap() ages.put("ada", 36) ages.put("alan", 41) val age : Int = (ages.get("ada")).getOrElse(0) println( "ada " + age ) if ( ages.contains("alan") ) { println( "alan is in the map" ) }}Definition: compiler/Lang.rgr, line 9051
get
(get map key) → <optional>T
get(map: [K:T], key: K)Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: default template
- Dart: default template
- Swift: default template
- C#: own template
- C++: own template
- PHP: default template
- Scala: own template
Definition: compiler/Lang.rgr, line 9174
has
(has map key) → boolean
has(map: [K:T], key: K)Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: own template
- Swift: own template
- C#: own template
- C++: own template
- PHP: own template
- Scala: own template
Write and read a hash map
class Main { sfn main:void () { def ages:[string:int] set ages "ada" 36 set ages "alan" 41 def age (?? (get ages "ada") 0) print ("ada " + age) if (has ages "alan") { print "alan is in the map" } }}let ages = {};ages["ada"] = 36;ages["alan"] = 41;const age = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0);console.log("ada " + age);if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map");}The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { let ages = {}; ages["ada"] = 36; ages["alan"] = 41; const age = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0); console.log("ada " + age); if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map"); }}__js_main();let ages : {[key:string]:number} | undefined = {};ages["ada"] = 36;ages["alan"] = 41;const age : number = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0);console.log("ada " + age);if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map");}The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { let ages : {[key:string]:number} | undefined = {}; ages["ada"] = 36; ages["alan"] = 41; const age : number = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0); console.log("ada " + age); if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map"); }}__js_main();var ages map[string]int64 = make(map[string]int64);ages["ada"] = int64(36);ages["alan"] = int64(41);var age int64= (func() int64 { if r_get_string_int64(ages, "ada").has_value { return r_get_string_int64(ages, "ada").value.(int64) } else { return int64(0)} }());fmt.Println( strings.Join([]string{ "ada ",strconv.FormatInt(age, 10) }, "") )if r_has_key_string_int64(ages, "alan") { fmt.Println( "alan is in the map" )}The complete file
package mainimport ( "strings" "strconv" "fmt")
type GoNullable struct { value interface{} has_value bool}
func r_get_string_int64( a map[string]int64, key string ) *GoNullable { res := new(GoNullable) v, ok := a[key] if ok { res.has_value = true res.value = v return res } res.has_value = false return res}func r_has_key_string_int64( a map[string]int64, key string ) bool { _, ok := a[key] return ok
}type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var ages map[string]int64 = make(map[string]int64); ages["ada"] = int64(36); ages["alan"] = int64(41); var age int64= (func() int64 { if r_get_string_int64(ages, "ada").has_value { return r_get_string_int64(ages, "ada").value.(int64) } else { return int64(0)} }()); fmt.Println( strings.Join([]string{ "ada ",strconv.FormatInt(age, 10) }, "") ) if r_has_key_string_int64(ages, "alan") { fmt.Println( "alan is in the map" ) }}The compiler does not write Rust code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?The compiler does not write Python code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?RgArgs.args = args;HashMap<String,Integer> ages = new HashMap<String,Integer>();ages.put("ada", 36);ages.put("alan", 41);final Integer age = (ages.get("ada") != null ) ? ages.get("ada") : 0;System.out.println(String.valueOf( "ada " + age ) );if ( ages.containsKey("alan") ) { System.out.println(String.valueOf( "alan is in the map" ) );}The complete file
import java.util.*;import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; HashMap<String,Integer> ages = new HashMap<String,Integer>(); ages.put("ada", 36); ages.put("alan", 41); final Integer age = (ages.get("ada") != null ) ? ages.get("ada") : 0; System.out.println(String.valueOf( "ada " + age ) ); if ( ages.containsKey("alan") ) { System.out.println(String.valueOf( "alan is in the map" ) ); } }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsvar ages : MutableMap<String,Int> = hashMapOf();ages.set("ada", 36)ages.set("alan", 41)val age : Int = (ages["ada"] ?: 0);println( "ada " + (age).toString() )if ( ages.containsKey("alan") ) { println( "alan is in the map" )}The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args var ages : MutableMap<String,Int> = hashMapOf(); ages.set("ada", 36) ages.set("alan", 41) val age : Int = (ages["ada"] ?: 0); println( "ada " + (age).toString() ) if ( ages.containsKey("alan") ) { println( "alan is in the map" ) }}__g_args = args;Map<String, int> ages = {};ages["ada"] = 36;ages["alan"] = 41;int age = (ages["ada"] ?? 0);print( "ada " + (age).toString() );if ( ages.containsKey("alan") ) { print( "alan is in the map" );}The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; Map<String, int> ages = {}; ages["ada"] = 36; ages["alan"] = 41; int age = (ages["ada"] ?? 0); print( "ada " + (age).toString() ); if ( ages.containsKey("alan") ) { print( "alan is in the map" ); }}var ages : [String:Int] = [String:Int]()ages["ada"] = 36;ages["alan"] = 41;let age : Int = (ages["ada"] ?? 0)print("ada " + String(age))if ( ages["alan"] != nil ) { print("alan is in the map")}The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { var ages : [String:Int] = [String:Int]() ages["ada"] = 36; ages["alan"] = 41; let age : Int = (ages["ada"] ?? 0) print("ada " + String(age)) if ( ages["alan"] != nil ) { print("alan is in the map") }}__main__swift()Dictionary<String,int> ages = new Dictionary<String,int>();ages["ada"] = 36;ages["alan"] = 41;int age = ((ages.ContainsKey("ada") ? (int?)ages["ada"] : null) ?? 0);Console.WriteLine("ada " + age);if ( ages.ContainsKey("alan") ) { Console.WriteLine("alan is in the map");}The complete file
using System;using System.Collections;using System.Collections.Generic;class Main { static void Main( string [] args ) { Dictionary<String,int> ages = new Dictionary<String,int>(); ages["ada"] = 36; ages["alan"] = 41; int age = ((ages.ContainsKey("ada") ? (int?)ages["ada"] : null) ?? 0); Console.WriteLine("ada " + age); if ( ages.ContainsKey("alan") ) { Console.WriteLine("alan is in the map"); } }}The compiler does not write C++ code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?$ages = array();$ages["ada"] = 36;$ages["alan"] = 41;$age = ($ages["ada"] ?? 0);echo( "ada " . $age . "\n");if ( array_key_exists("alan" , $ages ) ) { echo( "alan is in the map" . "\n");}The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$ages = array();$ages["ada"] = 36;$ages["alan"] = 41;$age = ($ages["ada"] ?? 0);echo( "ada " . $age . "\n");if ( array_key_exists("alan" , $ages ) ) { echo( "alan is in the map" . "\n");}var ages : collection.mutable.HashMap[String, Int] = new collection.mutable.HashMap()ages.put("ada", 36)ages.put("alan", 41)val age : Int = (ages.get("ada")).getOrElse(0)println( "ada " + age )if ( ages.contains("alan") ) { println( "alan is in the map" )}The complete file
import scala.collection.mutablecase class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { var ages : collection.mutable.HashMap[String, Int] = new collection.mutable.HashMap() ages.put("ada", 36) ages.put("alan", 41) val age : Int = (ages.get("ada")).getOrElse(0) println( "ada " + age ) if ( ages.contains("alan") ) { println( "alan is in the map" ) }}Definition: compiler/Lang.rgr, line 9011
keys
(keys map) → [string]
keys(map: [string:T])https://stackoverflow.com/questions/41690156/how-to-get-the-keys-as-string-array-from-map-in-go-lang https://stackoverflow.com/questions/110157/how-to-retrieve-all-keys-or-values-from-a-stdmap-and-put-them-into-a-vector
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: own template
- Swift: own template
- C#: own template
- C++: own template
- PHP: own template
- Scala: own template
Definition: compiler/Lang.rgr, line 7786
map_clear
(map_clear map) → void
map_clear(map: [K:T])Remove every entry of a map IN PLACE. On C++ this keeps the rg_ordered_map's buffers (capacity survives a clear), which is what makes pooled scopes reusable without re-allocating their tables.
Target support
- JavaScript: own template
- TypeScript: own template
- Go: own template
- Rust: own template
- Python: own template
- Java: own template
- Kotlin: own template
- Dart: own template
- Swift: own template
- C#: default template
- C++: own template
- PHP: own template
- Scala: own template
Definition: compiler/Lang.rgr, line 10122
set
(set map key value) → void
set(map: [K:T], key: K, value: T)Target support
- JavaScript: default template
- TypeScript: default template
- Go: default template
- Rust: own template
- Python: default template
- Java: own template
- Kotlin: own template
- Dart: default template
- Swift: default template
- C#: default template
- C++: own template
- PHP: own template
- Scala: own template
Write and read a hash map
class Main { sfn main:void () { def ages:[string:int] set ages "ada" 36 set ages "alan" 41 def age (?? (get ages "ada") 0) print ("ada " + age) if (has ages "alan") { print "alan is in the map" } }}let ages = {};ages["ada"] = 36;ages["alan"] = 41;const age = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0);console.log("ada " + age);if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map");}The complete file
class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { let ages = {}; ages["ada"] = 36; ages["alan"] = 41; const age = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0); console.log("ada " + age); if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map"); }}__js_main();let ages : {[key:string]:number} | undefined = {};ages["ada"] = 36;ages["alan"] = 41;const age : number = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0);console.log("ada " + age);if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map");}The complete file
export class Main { constructor() { }}/* static JavaSript main routine at the end of the JS file */function __js_main() { let ages : {[key:string]:number} | undefined = {}; ages["ada"] = 36; ages["alan"] = 41; const age : number = (( Object.prototype.hasOwnProperty.call(ages, "ada") ? ages["ada"] : undefined ) ?? 0); console.log("ada " + age); if ( ( typeof(ages["alan"] ) != "undefined" && Object.prototype.hasOwnProperty.call(ages, "alan") ) ) { console.log("alan is in the map"); }}__js_main();var ages map[string]int64 = make(map[string]int64);ages["ada"] = int64(36);ages["alan"] = int64(41);var age int64= (func() int64 { if r_get_string_int64(ages, "ada").has_value { return r_get_string_int64(ages, "ada").value.(int64) } else { return int64(0)} }());fmt.Println( strings.Join([]string{ "ada ",strconv.FormatInt(age, 10) }, "") )if r_has_key_string_int64(ages, "alan") { fmt.Println( "alan is in the map" )}The complete file
package mainimport ( "strings" "strconv" "fmt")
type GoNullable struct { value interface{} has_value bool}
func r_get_string_int64( a map[string]int64, key string ) *GoNullable { res := new(GoNullable) v, ok := a[key] if ok { res.has_value = true res.value = v return res } res.has_value = false return res}func r_has_key_string_int64( a map[string]int64, key string ) bool { _, ok := a[key] return ok
}type Main struct {}
func CreateNew_Main() *Main { me := new(Main) return me;}func main() { var ages map[string]int64 = make(map[string]int64); ages["ada"] = int64(36); ages["alan"] = int64(41); var age int64= (func() int64 { if r_get_string_int64(ages, "ada").has_value { return r_get_string_int64(ages, "ada").value.(int64) } else { return int64(0)} }()); fmt.Println( strings.Join([]string{ "ada ",strconv.FormatInt(age, 10) }, "") ) if r_has_key_string_int64(ages, "alan") { fmt.Println( "alan is in the map" ) }}The compiler does not write Rust code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?The compiler does not write Python code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?RgArgs.args = args;HashMap<String,Integer> ages = new HashMap<String,Integer>();ages.put("ada", 36);ages.put("alan", 41);final Integer age = (ages.get("ada") != null ) ? ages.get("ada") : 0;System.out.println(String.valueOf( "ada " + age ) );if ( ages.containsKey("alan") ) { System.out.println(String.valueOf( "alan is in the map" ) );}The complete file
import java.util.*;import java.io.*;
public class Main {
public static void main(String [] args ) { RgArgs.args = args; HashMap<String,Integer> ages = new HashMap<String,Integer>(); ages.put("ada", 36); ages.put("alan", 41); final Integer age = (ages.get("ada") != null ) ? ages.get("ada") : 0; System.out.println(String.valueOf( "ada " + age ) ); if ( ages.containsKey("alan") ) { System.out.println(String.valueOf( "alan is in the map" ) ); } }}
public class RgArgs { public static String[] args = new String[0];}__g_args = argsvar ages : MutableMap<String,Int> = hashMapOf();ages.set("ada", 36)ages.set("alan", 41)val age : Int = (ages["ada"] ?: 0);println( "ada " + (age).toString() )if ( ages.containsKey("alan") ) { println( "alan is in the map" )}The complete file
class Main {
}
var __g_args : Array<String> = arrayOf()
fun main(args : Array<String>) { __g_args = args var ages : MutableMap<String,Int> = hashMapOf(); ages.set("ada", 36) ages.set("alan", 41) val age : Int = (ages["ada"] ?: 0); println( "ada " + (age).toString() ) if ( ages.containsKey("alan") ) { println( "alan is in the map" ) }}__g_args = args;Map<String, int> ages = {};ages["ada"] = 36;ages["alan"] = 41;int age = (ages["ada"] ?? 0);print( "ada " + (age).toString() );if ( ages.containsKey("alan") ) { print( "alan is in the map" );}The complete file
class Main {}
List<String> __g_args = <String>[];
void main(List<String> args) { __g_args = args; Map<String, int> ages = {}; ages["ada"] = 36; ages["alan"] = 41; int age = (ages["ada"] ?? 0); print( "ada " + (age).toString() ); if ( ages.containsKey("alan") ) { print( "alan is in the map" ); }}var ages : [String:Int] = [String:Int]()ages["ada"] = 36;ages["alan"] = 41;let age : Int = (ages["ada"] ?? 0)print("ada " + String(age))if ( ages["alan"] != nil ) { print("alan is in the map")}The complete file
func ==(l: Main, r: Main) -> Bool { return l === r}final class Main : Hashable { func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(self)) }}// Main entry pointfunc __main__swift() { var ages : [String:Int] = [String:Int]() ages["ada"] = 36; ages["alan"] = 41; let age : Int = (ages["ada"] ?? 0) print("ada " + String(age)) if ( ages["alan"] != nil ) { print("alan is in the map") }}__main__swift()Dictionary<String,int> ages = new Dictionary<String,int>();ages["ada"] = 36;ages["alan"] = 41;int age = ((ages.ContainsKey("ada") ? (int?)ages["ada"] : null) ?? 0);Console.WriteLine("ada " + age);if ( ages.ContainsKey("alan") ) { Console.WriteLine("alan is in the map");}The complete file
using System;using System.Collections;using System.Collections.Generic;class Main { static void Main( string [] args ) { Dictionary<String,int> ages = new Dictionary<String,int>(); ages["ada"] = 36; ages["alan"] = 41; int age = ((ages.ContainsKey("ada") ? (int?)ages["ada"] : null) ?? 0); Console.WriteLine("ada " + age); if ( ages.ContainsKey("alan") ) { Console.WriteLine("alan is in the map"); } }}The compiler does not write C++ code for this example. The message is:
1: Could not match argument types for get1: !null? applies only to optional values; '(get ages"ada")' is non-optional ()1: Could not match argument types for get1: Could not match argument types for unwrap1: Could not match argument types for ?$ages = array();$ages["ada"] = 36;$ages["alan"] = 41;$age = ($ages["ada"] ?? 0);echo( "ada " . $age . "\n");if ( array_key_exists("alan" , $ages ) ) { echo( "alan is in the map" . "\n");}The complete file
<?php
class Main { function __construct( ) { }}/* static PHP main routine */$ages = array();$ages["ada"] = 36;$ages["alan"] = 41;$age = ($ages["ada"] ?? 0);echo( "ada " . $age . "\n");if ( array_key_exists("alan" , $ages ) ) { echo( "alan is in the map" . "\n");}var ages : collection.mutable.HashMap[String, Int] = new collection.mutable.HashMap()ages.put("ada", 36)ages.put("alan", 41)val age : Int = (ages.get("ada")).getOrElse(0)println( "ada " + age )if ( ages.contains("alan") ) { println( "alan is in the map" )}The complete file
import scala.collection.mutablecase class ScalaReturnValue(value:Any) extends Exception
// application main function for Mainobject AppMain extends App { var ages : collection.mutable.HashMap[String, Int] = new collection.mutable.HashMap() ages.put("ada", 36) ages.put("alan", 41) val age : Int = (ages.get("ada")).getOrElse(0) println( "ada " + age ) if ( ages.contains("alan") ) { println( "alan is in the map" ) }}Definition: compiler/Lang.rgr, line 9298
Ranger 3.5.1 · commit f323fd4 · development build