Created
September 28, 2019 23:38
-
-
Save Deleplace/76e101f1b9a9e05f00b736a338929355 to your computer and use it in GitHub Desktop.
Snapshot of the database of Programming Idioms
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"Id": 1, | |
"OrigId": 0, | |
"Title": "Print Hello World", | |
"LeadParagraph": "Print a literal string on standard output", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "ara", | |
"EditSummary": "[PHP] Close the PHP tag to make this work", | |
"LastEditedImplID": 2977, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 81, | |
"VersionDate": "2019-09-27T09:45:17.753274Z", | |
"Implementations": [ | |
{ | |
"Id": 1, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "", | |
"LanguageName": "Java", | |
"CodeBlock": "System.out.println(\"Hello World\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "Wohlfe", | |
"LanguageName": "Python", | |
"CodeBlock": "print(\"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/2/library/future_builtins.html", | |
"AuthorComment": "This is for Python 2, but maintains compatibility with Python 3.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:57:35.227864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "from __future__ import print_function", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 4, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "tuxiqae", | |
"LanguageName": "PHP", | |
"CodeBlock": "echo \"Hello World\" . PHP_EOL;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Use PHP_EOL instead of \\n", | |
"Version": 2, | |
"VersionDate": "2019-03-09T21:53:48.086715Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 5, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "fmt.Println(\"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/MItq-mdV36", | |
"DocumentationURL": "https://tour.golang.org/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"fmt\" ", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 6, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "gegtik", | |
"LanguageName": "JS", | |
"CodeBlock": "document.write(\"Hello World!\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This will print the output to the rendered browser document", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 7, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "printf(\"Hello World\\n\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdio.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 8, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "", | |
"LanguageName": "Csharp", | |
"CodeBlock": "System.Console.WriteLine(\"Hello World!\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 61, | |
"OrigId": 61, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "puts \"Hello World\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWcs/0", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-13T14:43:18.32236Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 70, | |
"OrigId": 70, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "Idiom Master", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::cout \u003c\u003c \"Hello World\\n\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 81, | |
"OrigId": 81, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "bugfry", | |
"LanguageName": "Rust", | |
"CodeBlock": "println!(\"Hello World\");", | |
"OriginalAttributionURL": "http://en.wikipedia.org/wiki/Rust_%28programming_language%29#Examples", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 121, | |
"OrigId": 121, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "unsc_savannah", | |
"LanguageName": "Ada", | |
"CodeBlock": "Put_Line (\"Hello World!\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:58:44.5952Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Text_IO;\r\nuse Ada.Text_IO;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 122, | |
"OrigId": 122, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Caml", | |
"CodeBlock": "print_endline \"Hello World!\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:04:09.983608Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 123, | |
"OrigId": 123, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(println \"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 124, | |
"OrigId": 124, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "writeln(\"Hello world!\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://dlang.org/phobos/std_stdio.html#.write", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:05:00.247156Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 125, | |
"OrigId": 125, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "print(\"Hello World\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:09:53.779417Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 127, | |
"OrigId": 127, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Erlang", | |
"CodeBlock": "io:format(\"~s~n\", [\"Hello, world!\"])", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:11:26.91955Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 128, | |
"OrigId": 128, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "dev-zero", | |
"LanguageName": "Fortran", | |
"CodeBlock": "print *, 'Hello, world!'", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "in modern Fortran (2003+) I would consider using the print statement more idiomatic than the write statement", | |
"Version": 3, | |
"VersionDate": "2019-09-26T15:57:37.092389Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 130, | |
"OrigId": 130, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(princ \"Hello, world!\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:11:46.527478Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 131, | |
"OrigId": 131, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "WriteLn('Hello, world!');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:11:55.637251Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 132, | |
"OrigId": 132, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "print \"Hello, world!\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:12:31.992822Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 133, | |
"OrigId": 133, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scala", | |
"CodeBlock": "println(\"Hello, World!\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:12:47.549482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 134, | |
"OrigId": 134, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(display \"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:12:56.019976Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 136, | |
"OrigId": 136, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Obj-C", | |
"CodeBlock": "NSLog(@\"Hello world\\n\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-29T00:13:06.569436Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#import \u003cstdio.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 137, | |
"OrigId": 137, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "Olli", | |
"LanguageName": "VB", | |
"CodeBlock": "System.Console.WriteLine(\"Hello World!\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://msdn.microsoft.com/en-us/library/aa309383(v=vs.71).aspx", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 377, | |
"OrigId": 377, | |
"Author": "christianhujer", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Prolog", | |
"CodeBlock": "write('Hello, world!\\n')", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 677, | |
"OrigId": 677, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lua", | |
"CodeBlock": "print(\"Hello World\")", | |
"OriginalAttributionURL": "http://www.lua.org/pil/1.html", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 799, | |
"OrigId": 799, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "ara", | |
"LanguageName": "Haskell", | |
"CodeBlock": "putStrLn \"Hello world!\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 895, | |
"OrigId": 895, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "IO.puts \"Hello World\"", | |
"OriginalAttributionURL": "http://elixir-lang.org/crash-course.html#elixir", | |
"DemoURL": "http://play.elixirbyexample.com/s/1ff8faa890", | |
"DocumentationURL": "http://elixir-lang.org/getting-started/io-and-the-file-system.html#the-io-module", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2017-02-07T23:38:09.08384Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1159, | |
"OrigId": 1159, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "Wohlfe", | |
"LanguageName": "Python", | |
"CodeBlock": "print(\"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This works in Python 3, and will work in Python 2 with the correct import.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:59:32.747154Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1213, | |
"OrigId": 1213, | |
"Author": "piou", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "piou", | |
"LanguageName": "D", | |
"CodeBlock": "pragma(msg, \"Hello World\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Compile-time hello world", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1306, | |
"OrigId": 1306, | |
"Author": "gegtik", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "J", | |
"LanguageName": "JS", | |
"CodeBlock": "console.log('Hello World');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This will print output to the console on any standard browser.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:04:40.065956Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1408, | |
"OrigId": 1408, | |
"Author": "Boris", | |
"CreationDate": "2016-02-18T16:57:54.865234Z", | |
"LastEditor": "Boris", | |
"LanguageName": "Prolog", | |
"CodeBlock": "format(\"Hello world~n\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:54.865234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1913, | |
"OrigId": 1913, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-11-30T21:43:36.899487Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "\"Hello World\" |\u003e IO.puts", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/d04a8cddd1", | |
"DocumentationURL": "http://elixir-lang.org/getting-started/io-and-the-file-system.html#the-io-module", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-02-07T23:38:27.032471Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2177, | |
"OrigId": 2177, | |
"Author": "Bart", | |
"CreationDate": "2017-11-10T22:03:56.739461Z", | |
"LastEditor": "Bart", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. hello.\nPROCEDURE DIVISION.\nDISPLAY \"Hello World!\".\nSTOP RUN.", | |
"OriginalAttributionURL": "https://open-cobol.sourceforge.io/historical/open-cobol/Hello-World-.html", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-11-10T22:03:56.739461Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2646, | |
"OrigId": 2646, | |
"Author": "d2alphame", | |
"CreationDate": "2019-06-20T21:33:32.914227Z", | |
"LastEditor": "d2alphame", | |
"LanguageName": "Perl", | |
"CodeBlock": "say \"Hello World\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Works with newer version of perl like perl 5.24. Requires enabling the 'say' feature in older perls. Prints 'Hello World' and adds a newline", | |
"Version": 1, | |
"VersionDate": "2019-06-20T21:33:32.914227Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2778, | |
"OrigId": 2778, | |
"Author": "DerArzt", | |
"CreationDate": "2019-09-26T15:02:07.545536Z", | |
"LastEditor": "mwsundberg", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(print \"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "sbcl common lisp dialect", | |
"Version": 2, | |
"VersionDate": "2019-09-26T20:07:57.478414Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2782, | |
"OrigId": 2782, | |
"Author": "DerArzt", | |
"CreationDate": "2019-09-26T15:03:48.2137Z", | |
"LastEditor": "DerArzt", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(format T \"Hello World\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:03:48.2137Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2835, | |
"OrigId": 2835, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2019-09-26T15:54:18.248965Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "fun main() {\n println(\"Hello world!\")\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://kotlinlang.org/docs/tutorials/kotlin-for-py/hello-world.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:54:18.248965Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2976, | |
"OrigId": 2976, | |
"Author": "munk-a", | |
"CreationDate": "2019-09-26T17:44:26.546645Z", | |
"LastEditor": "munk-a", | |
"LanguageName": "PHP", | |
"CodeBlock": "\u003c?='Hello World'?\u003e", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/29uGH", | |
"DocumentationURL": "", | |
"AuthorComment": "Using the short echo syntax, a non-deprecated short tag expression.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:44:26.546645Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2977, | |
"OrigId": 2977, | |
"Author": "munk-a", | |
"CreationDate": "2019-09-26T17:45:25.248739Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "?\u003eHello World\u003c?php // code can continue here...", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/fFhbE", | |
"DocumentationURL": "", | |
"AuthorComment": "Characters outside of execution blocks are immediately echoed.", | |
"Version": 2, | |
"VersionDate": "2019-09-27T09:45:17.750173Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3105, | |
"OrigId": 3105, | |
"Author": "gumbo59", | |
"CreationDate": "2019-09-26T21:33:21.449586Z", | |
"LastEditor": "gumbo59", | |
"LanguageName": "JS", | |
"CodeBlock": "console.log('Hello World')", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:33:21.449586Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 41, | |
"Rating": 2, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 2, | |
"OrigId": 0, | |
"Title": "Print Hello 10 times", | |
"LeadParagraph": "Loop to execute some code a constant number of times", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "", | |
"EditSummary": "New Kotlin implementation by user [dector]", | |
"LastEditedImplID": 3472, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/2/Hello_fading.png", | |
"Version": 98, | |
"VersionDate": "2019-09-28T21:49:56.396092Z", | |
"Implementations": [ | |
{ | |
"Id": 9, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "", | |
"LanguageName": "Java", | |
"CodeBlock": "for(int i=0;i\u003c10;i++)\n System.out.println(\"Hello\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 11, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "cissoid", | |
"LanguageName": "Python", | |
"CodeBlock": "for i in range(10):\n print(\"Hello\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Indention is mandatory", | |
"Version": 2, | |
"VersionDate": "2019-09-27T02:17:54.987284Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 12, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "for ($i = 0; $i \u003c 10; $i++) {\n echo 'Hello' . PHP_EOL;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Note the necessary newline (PHP_EOL), not to print every time on the same line", | |
"Version": 4, | |
"VersionDate": "2019-09-27T09:46:57.363938Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 13, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "jonno", | |
"LanguageName": "Go", | |
"CodeBlock": "for i := 0; i \u003c 10; i++ {\n\tfmt.Println(\"Hello\")\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/WAztzFAML99", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:00:52.123437Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"fmt\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 14, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "blakecallens", | |
"LanguageName": "JS", | |
"CodeBlock": "for (let i = 0; i \u003c 10; i++) {\n console.log(\"Hello\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "let quarantines the scope of i to the loop in ES6", | |
"Version": 5, | |
"VersionDate": "2019-09-26T16:54:56.477272Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 15, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "phrank", | |
"LanguageName": "C", | |
"CodeBlock": "for (int i = 0; i \u003c 10; i++) {\n printf(\"Hello\\n\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Note the necessary newline (\\n), not to print every time on the same line", | |
"Version": 3, | |
"VersionDate": "2019-09-27T19:09:57.06898Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 16, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "Vlad", | |
"LanguageName": "Csharp", | |
"CodeBlock": "for (int i = 0; i \u003c 10; i++)\n{\n System.Console.WriteLine(\"Hello\");\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T20:12:51.690495Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 60, | |
"OrigId": 60, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "10.times do\r\n puts \"Hello\"\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-04-18T21:21:10.003295Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 71, | |
"OrigId": 71, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "coltonriedel", | |
"LanguageName": "Cpp", | |
"CodeBlock": "for (int i = 0; i \u003c 10; ++i)\n cout \u003c\u003c \"Hello\\n\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2019-09-26T15:14:24.108305Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e\r\nusing namespace std;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 91, | |
"OrigId": 91, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "replicateM_ 10 $ putStrLn \"Hello\"", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/16004365/simple-haskell-loop#answer-16004389", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 147, | |
"OrigId": 147, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (hellos i)\n (if (\u003e i 0) \n (begin\n (display \"Hello\")\n (newline)\n (hellos (- i 1)))))\n(hellos 10)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://repl.it/SIH", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 200, | |
"OrigId": 200, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "for (var i = 0; i \u003c 10; i++) { \n print(\"Hello\");\n} ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#for-loops", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 2, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 288, | |
"OrigId": 288, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "print \"Hello\\n\" for 1 .. 10;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Note the necessary newline (\\n), not to print every time on the same line", | |
"Version": 3, | |
"VersionDate": "2016-01-08T09:05:07.320765Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 403, | |
"OrigId": 403, | |
"Author": "PEPP", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "kai", | |
"LanguageName": "Rust", | |
"CodeBlock": "for _ in 0..10 { println!(\"Hello\"); }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20for%20_%20in%200..10%20%7B%0A%20%20%20%20%20%20%20%20println!(%22Hello%22)%3B%0A%20%20%20%20%7D%0A%7D\u0026version=stable", | |
"DocumentationURL": "", | |
"AuthorComment": "0..10 syntax creates range iterator.\r\n\r\nYou can leave out variable name with underscore if you do not want to use it.", | |
"Version": 3, | |
"VersionDate": "2018-04-15T01:48:57.189848Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 515, | |
"OrigId": 515, | |
"Author": "schveiguy", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "dude", | |
"LanguageName": "D", | |
"CodeBlock": "foreach(i; 0..10)\n writeln(\"Hello\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "use foreach with a numeric range instead of for whenever possible to avoid subtle errors. Also allows nice type inferrence.", | |
"Version": 3, | |
"VersionDate": "2019-09-27T16:41:04.43083Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 596, | |
"OrigId": 596, | |
"Author": "adam", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "adam", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var\n i: integer;\nbegin\n for i:=1 to 10 do\n WriteLn('Hello');\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 811, | |
"OrigId": 811, | |
"Author": "jfacorro", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(dotimes [_ 10]\n (println \"Hello\"))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/dotimes", | |
"AuthorComment": "The character __ means we don't want to bind the value to a symbol.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 907, | |
"OrigId": 907, | |
"Author": "anonyfox", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "llama", | |
"LanguageName": "Elixir", | |
"CodeBlock": "1..10 |\u003e Enum.each(fn _ -\u003e IO.puts \"Hello\" end)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://hexdocs.pm/elixir/1.0.5/Enum.html#each/2", | |
"AuthorComment": "The pipe operator is very common in elixir and is used to chain function calls", | |
"Version": 7, | |
"VersionDate": "2019-09-26T21:55:50.987591Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 993, | |
"OrigId": 993, | |
"Author": "yanoo", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "SidhArt", | |
"LanguageName": "Ruby", | |
"CodeBlock": "10.times { p 'Hello' }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-09-27T14:42:12.583718Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1063, | |
"OrigId": 1063, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:23.746597Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "lists:foreach(\n fun(_) -\u003e\n io:format(\"Hello~n\")\n end, lists:seq(1, 10)).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=2ff3", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=0\u0026search=lists:for#foreach/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:23.746597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1200, | |
"OrigId": 1200, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-01-08T09:04:19.951398Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "say \"Hello\" for 1 .. 10;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://perldoc.perl.org/functions/say.html", | |
"AuthorComment": "Recent (5.10 and later) versions of Perl also provide\r\nsay function, which automatically adds the newline.", | |
"Version": 1, | |
"VersionDate": "2016-01-08T09:04:19.951398Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1294, | |
"OrigId": 1294, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-16T15:01:07.497857Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "for I in 1 .. 10 loop\r\n Put_Line (\"Hello\");\r\nend loop;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/9xC8us", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T15:01:07.497857Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Text_IO;\r\nuse Ada.Text_IO;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1302, | |
"OrigId": 1302, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T15:14:01.446482Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "for i=1, 10 do\r\n\tprint('Hello')\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T15:14:01.446482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1434, | |
"OrigId": 1434, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:29:53.718803Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "(0 until 10).foreach( _ =\u003e println(\"Hello\"))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:29:53.718803Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1493, | |
"OrigId": 1493, | |
"Author": "myguel", | |
"CreationDate": "2016-02-17T11:00:17.942564Z", | |
"LastEditor": "ekn", | |
"LanguageName": "Python", | |
"CodeBlock": "print(\"Hello\\n\"*10)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "python 3", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:27:12.99681Z", | |
"Rating": 2, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2081, | |
"OrigId": 2081, | |
"Author": "Bzzzzzzzz", | |
"CreationDate": "2017-08-06T15:36:05.478691Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "iota(0,10).each!(a =\u003e \"Hello\".writeln);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/MjsOpv", | |
"DocumentationURL": "https://dlang.org/phobos/std_algorithm_iteration.html#each", | |
"AuthorComment": "_iota generates an iterable sequence of number.\r\n_each is a higher order function.\r\n_Hello is written using _UFCS in a delegate literal.", | |
"Version": 3, | |
"VersionDate": "2017-08-07T19:40:40.911559Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio : writeln;\r\nimport std.range : iota;\r\nimport std.algorithm.iteration : each;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2240, | |
"OrigId": 2240, | |
"Author": "GCentelles", | |
"CreationDate": "2018-03-04T08:35:26.939701Z", | |
"LastEditor": "alctyus", | |
"LanguageName": "Obj-C", | |
"CodeBlock": "for (NSInteger i=0;i\u003c10;i++){\nNSLog(@\"Hello world\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:25:28.89192Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2241, | |
"OrigId": 2241, | |
"Author": "wobray", | |
"CreationDate": "2018-03-06T16:07:00.183399Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(loop repeat 10 do (write-line \"Hello\"))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:10:08.775047Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2872, | |
"OrigId": 2872, | |
"Author": "bigtoe416", | |
"CreationDate": "2019-09-26T16:36:29.013121Z", | |
"LastEditor": "bigtoe416", | |
"LanguageName": "Ruby", | |
"CodeBlock": "puts \"Hello\\n\" * 10", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:36:29.013121Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2893, | |
"OrigId": 2893, | |
"Author": "athenot", | |
"CreationDate": "2019-09-26T16:48:02.733148Z", | |
"LastEditor": "athenot", | |
"LanguageName": "Perl", | |
"CodeBlock": "print \"Hello\\n\" x 10;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://perldoc.perl.org/perlop.html#Multiplicative-Operators", | |
"AuthorComment": "Without using a loop, using the repeat operator.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:48:02.733148Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2895, | |
"OrigId": 2895, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:49:08.337314Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "program main\n implicit none\n integer :: i\n do i=1,10\n write (*,'(A)') \"Hello\"\n end do\nend program main\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:49:08.337314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2953, | |
"OrigId": 2953, | |
"Author": "jtang", | |
"CreationDate": "2019-09-26T17:27:09.215245Z", | |
"LastEditor": "mjh", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "(0..9).forEach {\n println(\"Hello\")\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://www.programiz.com/kotlin-programming/for-loop", | |
"AuthorComment": "0..9 is inclusive", | |
"Version": 3, | |
"VersionDate": "2019-09-26T21:49:27.880377Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3026, | |
"OrigId": 3026, | |
"Author": "Miltnoid", | |
"CreationDate": "2019-09-26T19:10:31.600418Z", | |
"LastEditor": "Miltnoid", | |
"LanguageName": "Caml", | |
"CodeBlock": "let rec n_hello_worlds\n (n : int)\n : unit =\n if n = 0 then\n ()\n else\n (print_endline \"Hello World!\";\n n_hello_worlds (n-1))\n\nn_hello_worlds 10", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:10:31.600418Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3107, | |
"OrigId": 3107, | |
"Author": "gumbo59", | |
"CreationDate": "2019-09-26T21:37:44.49132Z", | |
"LastEditor": "gumbo59", | |
"LanguageName": "JS", | |
"CodeBlock": "let count = 0;\nwhile (count \u003c 10) {\n count++; \n console.log('Hello');\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T21:38:14.633038Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3110, | |
"OrigId": 3110, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-26T21:43:09.67553Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "for x = 1 to 10\n console.writeline(\"Hello\")\nnext x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Iterate from 1 to 10; print Hello on a new line", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:43:09.67553Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "system.io", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3117, | |
"OrigId": 3117, | |
"Author": "yatin", | |
"CreationDate": "2019-09-26T21:52:15.599123Z", | |
"LastEditor": "yatin", | |
"LanguageName": "Python", | |
"CodeBlock": "print(\"Hello\\n\"*10)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/BF7qbj", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:52:15.599123Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3306, | |
"OrigId": 3306, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-27T20:04:38.290266Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. hello 10 times.\nPROCEDURE DIVISION.\nPERFORM 10 TIMES\n DISPLAY \"Hello\"\nEND-PERFORM\nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T20:04:38.290266Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3472, | |
"OrigId": 3472, | |
"Author": "dector", | |
"CreationDate": "2019-09-28T21:49:56.391621Z", | |
"LastEditor": "dector", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "repeat(10) {\n println(\"Hello\")\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://pl.kotl.in/HCyRUAWU0", | |
"DocumentationURL": "https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-28T21:49:56.391621Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 38, | |
"Rating": 1, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 3, | |
"OrigId": 0, | |
"Title": "Create a procedure", | |
"LeadParagraph": "Like a function which doesn't return any value, thus has only side effects (e.g. Print to standard output)", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "", | |
"EditSummary": "New VB implementation by user [EvilGenius]", | |
"LastEditedImplID": 3372, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 43, | |
"VersionDate": "2019-09-27T23:27:31.399355Z", | |
"Implementations": [ | |
{ | |
"Id": 17, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "void finish(String name){\r\n System.out.println(\"My job here is done. Goodbye \" + name);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_void means \"no return value\".", | |
"Version": 2, | |
"VersionDate": "2016-08-23T13:44:06.825866Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 19, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "def finish(name):\n\tprint \"My job here is done. Goodbye \" + name", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 20, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func finish(name string) {\r\n fmt.Println(\"My job here is done. Good bye \" + name)\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/NSbp6jceZH", | |
"DocumentationURL": "", | |
"AuthorComment": "There is no return type in the signature, before the { .", | |
"Version": 3, | |
"VersionDate": "2016-08-23T13:45:31.074278Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"fmt\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 21, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "", | |
"LanguageName": "C", | |
"CodeBlock": "void finish(){\n printf(\"My job here is done.\\n\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 62, | |
"OrigId": 62, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def finish( name )\r\n puts \"My job here is done. Goodbye #{name}\"\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Ruby methods always return something; in this case _nil, the return value of _puts\r\n\r\n ", | |
"Version": 2, | |
"VersionDate": "2016-04-18T20:10:56.270488Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 72, | |
"OrigId": 72, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "rpm", | |
"LanguageName": "Cpp", | |
"CodeBlock": "void finish(char* name){\n cout \u003c\u003c \"My job here is done. Goodbye \" \u003c\u003c name \u003c\u003c \"\\n\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T14:44:29.586105Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e\r\nusing namespace std;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 99, | |
"OrigId": 99, | |
"Author": "Tcha", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Tcha", | |
"LanguageName": "JS", | |
"CodeBlock": "var bli = function() { \n\tconsole.log('Hello World!!!');\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 100, | |
"OrigId": 100, | |
"Author": "Tcha", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Tcha", | |
"LanguageName": "JS", | |
"CodeBlock": "function bli() { \n\tconsole.log('Hello World!!!');\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 148, | |
"OrigId": 148, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Kotik", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (finish name)\r\n (display \"My job here is done. Goodbye \")\r\n (display name)\r\n (newline))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/SII/3", | |
"DocumentationURL": "", | |
"AuthorComment": "This is a short syntax for a lambda definition.", | |
"Version": 3, | |
"VersionDate": "2017-01-11T10:22:49.196858Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 149, | |
"OrigId": 149, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Kotik", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define finish\r\n (lambda (name)\r\n (display \"My job here is done. Goodbye \")\r\n (display name)\r\n (newline)))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/SII/2", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-01-11T10:21:44.881107Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 290, | |
"OrigId": 290, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub myProcedureName {\r\n # Get subroutine arguments\r\n my ($arg1, $arg2, @rest) = @_;\r\n # do stuff\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-04-19T00:27:45.308838Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 406, | |
"OrigId": 406, | |
"Author": "PEPP", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn finish(name : \u0026str) {\n println!(\"My job here is done. Goodbye {}\", name);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/KqExyU", | |
"DocumentationURL": "", | |
"AuthorComment": "The actual return type is Unit, typed '()' and can be ommited from function signature.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 508, | |
"OrigId": 508, | |
"Author": "bbtemp", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "bbtemp", | |
"LanguageName": "D", | |
"CodeBlock": "void finish() {\n\twriteln(\"I' m a done job\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 543, | |
"OrigId": 543, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "function finish($name) \n{\n echo \"My job here is done. Goodbye $name\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 602, | |
"OrigId": 602, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "void finish(String name) {\n print(\"My job here is done. Goodbye $name.\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/732920a06cbc81d4a47e", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 609, | |
"OrigId": 609, | |
"Author": "flappertapper", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "flappertapper", | |
"LanguageName": "Pascal", | |
"CodeBlock": "Procedure finish(name: String);\nBegin\n WriteLn('My job here is done. Goodbye ', name);\nEnd;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 803, | |
"OrigId": 803, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "f x = print x :: IO ()\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "actually returns the side effecting action as reusable value", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 809, | |
"OrigId": 809, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(defn main- [\u0026 args]\n (println \"I got all this arguments \" args \" and now I'm returning nil. Peace out!\"))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/defn", | |
"AuthorComment": "The syntax \"\u0026 args\" in the arguments vector means this function can take any number of arguments. ", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 900, | |
"OrigId": 900, | |
"Author": "rrrene", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "def finish(name) do\r\n IO.puts \"My job here is done. Goodbye #{name}\"\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/a3d5a356bb", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-11-30T22:32:10.95979Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1066, | |
"OrigId": 1066, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-spec procedure() -\u003e _.\nprocedure() -\u003e io:format(\"#YOLO!~n\").", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "There is no way to avoid _returning a value here. This function returns _ok. But you can add -spec to say that you should not _care about the result.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1304, | |
"OrigId": 1304, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "function finish(name)\n\tprint('My job here is done. Goodbye, '..name)\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1311, | |
"OrigId": 1311, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "procedure Finish (Name : String) is\nbegin\n Put_Line (\"My job here is done. Goodbye \" \u0026 Name);\nend Finish;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1346, | |
"OrigId": 1346, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "public void Print(string text)\n{\n Console.WriteLine(text);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "System;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1435, | |
"OrigId": 1435, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:55.28067Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "def doSomething(input: String): Unit = {\n println(\"Did something\")\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.28067Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2372, | |
"OrigId": 2372, | |
"Author": "A", | |
"CreationDate": "2018-08-12T11:26:19.78712Z", | |
"LastEditor": "A", | |
"LanguageName": "Python", | |
"CodeBlock": "def a():\n\tpass", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Without side effects", | |
"Version": 1, | |
"VersionDate": "2018-08-12T11:26:19.78712Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2824, | |
"OrigId": 2824, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:40:26.30319Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defun show (message)\n (format t \"Hello: ~a\" message)\n (values))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:40:26.30319Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2890, | |
"OrigId": 2890, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:47:04.153122Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "let do_something arg1 arg2: unit =\n\tprint_endline \"foo\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:47:04.153122Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2897, | |
"OrigId": 2897, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:50:36.512439Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "module foo\n implicit none\ncontains\n subroutine bar\n print *,\"Hello\"\n end subroutine bar\nend module foo", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Modern Fortran should use modules and implicit none, so I added both.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:50:36.512439Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2978, | |
"OrigId": 2978, | |
"Author": "munk-a", | |
"CreationDate": "2019-09-26T17:49:03.913813Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function()\n{\n echo \"Hello World\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/UYmtT", | |
"DocumentationURL": "", | |
"AuthorComment": "This is an unnamed function, it can be bound to a variable or else immediately executed - the demo has both usages in it.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:14:05.040043Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2989, | |
"OrigId": 2989, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:56:35.054644Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "fun proc(x: String) { print(x) }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:56:35.054644Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3112, | |
"OrigId": 3112, | |
"Author": "gumbo59", | |
"CreationDate": "2019-09-26T21:44:28.703553Z", | |
"LastEditor": "gumbo59", | |
"LanguageName": "JS", | |
"CodeBlock": "let dog = 'Poodle';\n\nconst dogAlert = () =\u003e alert(dog);\n\ndogAlert();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:44:28.703553Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3372, | |
"OrigId": 3372, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:27:31.395832Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Public Sub procedure()\n\nEnd Sub", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:27:31.395832Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 32, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 4, | |
"OrigId": 0, | |
"Title": "Create a function which returns the square of an integer", | |
"LeadParagraph": "", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "gibe", | |
"EditSummary": "New VB implementation by user [EvilGenius]", | |
"LastEditedImplID": 3362, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 63, | |
"VersionDate": "2019-09-27T23:14:09.292914Z", | |
"Implementations": [ | |
{ | |
"Id": 22, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "", | |
"LanguageName": "Java", | |
"CodeBlock": "int square(int x){\n return x*x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 24, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "nickname", | |
"LanguageName": "Python", | |
"CodeBlock": "def square(x):\n return x*x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "You don't have to explicitly write the return type", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 25, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "russmack", | |
"LanguageName": "Go", | |
"CodeBlock": "func square(x int) int {\r\n return x*x\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The return type is after the parameter list", | |
"Version": 2, | |
"VersionDate": "2017-02-05T02:47:34.478919Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 26, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "", | |
"LanguageName": "C", | |
"CodeBlock": "int square(int x){\n return x*x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 75, | |
"OrigId": 75, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Cpp", | |
"CodeBlock": "int square(int x){\n return x*x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 90, | |
"OrigId": 90, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def square(x)\r\n x*x\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWrh/1", | |
"DocumentationURL": "", | |
"AuthorComment": "The last expression is returned by default", | |
"Version": 3, | |
"VersionDate": "2016-11-13T22:46:30.489233Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 101, | |
"OrigId": 101, | |
"Author": "Tcha", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "function square(x) { \n\treturn x*x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:50:24.036141Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 102, | |
"OrigId": 102, | |
"Author": "Tcha", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "function square(x) { \n\treturn x * x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:50:45.116631Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 150, | |
"OrigId": 150, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define square\n (lambda (x)\n (* x x)))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://repl.it/SIJ", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 151, | |
"OrigId": 151, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (square x)\n (* x x))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://repl.it/SIJ/1", | |
"DocumentationURL": "", | |
"AuthorComment": "This is a short syntax for a lambda definition.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 291, | |
"OrigId": 291, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub next_integer {\n my $val;\n\n return 1+$val;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "While perl will return the last value of the last expression to the caller, you'll want to use the resturn statement to make it explicit.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 405, | |
"OrigId": 405, | |
"Author": "PEPP", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "PEPP", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn function(x : u32) -\u003e u32 { x * x }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Last expression in function (actually block in general) is used as a return value.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 519, | |
"OrigId": 519, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "schveiguy", | |
"LanguageName": "D", | |
"CodeBlock": "int square(int x) {\n return x*x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 604, | |
"OrigId": 604, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "int square(int x) =\u003e x * x;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/3a60c2e51fa567cccab5", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 612, | |
"OrigId": 612, | |
"Author": "flappertapper", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "flappertapper", | |
"LanguageName": "Pascal", | |
"CodeBlock": "Function square(x: Integer): Integer;\nBegin\n Result := x*x;\nEnd;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 804, | |
"OrigId": 804, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "googol = 10 ^ 100 :: Integer\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 815, | |
"OrigId": 815, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(defn square [x]\n (* x x))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 816, | |
"OrigId": 816, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-spec square(integer()) -\u003e integer().\nsquare(X) when is_integer(X) -\u003e X * X.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The guard guarantees that the return value will be an integer. ", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 917, | |
"OrigId": 917, | |
"Author": "knewter", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "@spec square(integer) :: integer\r\ndef square(x) when is_integer(x), do: x*x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/5ac6139c77", | |
"DocumentationURL": "", | |
"AuthorComment": "The guard guarantees that the return value is an integer. The spec lets dialyzer warn you if you use this without something guaranteed to be an integer, or where the return value is used somewhere that an integer is invalid.", | |
"Version": 2, | |
"VersionDate": "2016-11-30T22:38:10.044597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1289, | |
"OrigId": 1289, | |
"Author": "djxfade", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function square(int $x): int\n{\n return $x * $x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:08:24.894977Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1305, | |
"OrigId": 1305, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "function square(x)\n\treturn x*x\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1312, | |
"OrigId": 1312, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "function Square (X : Integer) return Integer is\nbegin\n return X * X;\nend Square;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1345, | |
"OrigId": 1345, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "int Square(int x)\n{\n return x * x;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.3769Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1407, | |
"OrigId": 1407, | |
"Author": "mg", | |
"CreationDate": "2016-02-18T16:57:55.3769Z", | |
"LastEditor": "Ben", | |
"LanguageName": "Scala", | |
"CodeBlock": "def square(x:Int): Int = x*x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T14:55:23.16079Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2070, | |
"OrigId": 2070, | |
"Author": "Bzzzzzzzzz", | |
"CreationDate": "2017-07-30T12:03:19.700624Z", | |
"LastEditor": "Bzzzzzzzzz", | |
"LanguageName": "D", | |
"CodeBlock": "alias fun = (int a){return a * a;};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://ideone.com/4wIEOE", | |
"DocumentationURL": "https://dlang.org/spec/expression.html#FunctionLiteral", | |
"AuthorComment": "Using a _delegate _literal.", | |
"Version": 2, | |
"VersionDate": "2017-07-30T12:03:42.720588Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2293, | |
"OrigId": 2293, | |
"Author": "hrschueler", | |
"CreationDate": "2018-04-17T16:54:36.827783Z", | |
"LastEditor": "xaedes", | |
"LanguageName": "Haskell", | |
"CodeBlock": "square x = x * x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:30:31.851754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2295, | |
"OrigId": 2295, | |
"Author": "alchemist", | |
"CreationDate": "2018-04-18T06:08:55.919333Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "const square = (x) =\u003e x * x;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:49:45.283232Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2840, | |
"OrigId": 2840, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:56:19.829066Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defun square (x)\n (* x x))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:56:19.829066Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2900, | |
"OrigId": 2900, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:51:40.671526Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "let square x = x*x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:51:40.671526Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2905, | |
"OrigId": 2905, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:53:55.057023Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "module foo\n implicit none\ncontains\n function square(i) result(res)\n integer, intent(in) :: i\n integer :: res\n res = i * i\n end function square\nend module foo\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Modern Fortran code should use modules, so I put the function into one.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:53:55.057023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2921, | |
"OrigId": 2921, | |
"Author": "miszczu", | |
"CreationDate": "2019-09-26T17:03:49.234574Z", | |
"LastEditor": "miszczu", | |
"LanguageName": "Python", | |
"CodeBlock": "def square(x):\n return x**2", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "You can use power operator", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:03:49.234574Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2965, | |
"OrigId": 2965, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:37:34.536418Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "fun square(x: Int) = x * x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:37:34.536418Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2980, | |
"OrigId": 2980, | |
"Author": "Jai", | |
"CreationDate": "2019-09-26T17:49:50.089744Z", | |
"LastEditor": "Jai", | |
"LanguageName": "JS", | |
"CodeBlock": "function square(n){\nreturn n*n;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:49:50.089744Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3039, | |
"OrigId": 3039, | |
"Author": "Jeff McMahan", | |
"CreationDate": "2019-09-26T19:38:04.212149Z", | |
"LastEditor": "Jeff McMahan", | |
"LanguageName": "JS", | |
"CodeBlock": "const square = n =\u003e n**2", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation", | |
"AuthorComment": "The exponentiation operator is the most expressive way to do this.", | |
"Version": 3, | |
"VersionDate": "2019-09-26T19:38:59.856561Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3054, | |
"OrigId": 3054, | |
"Author": "jm", | |
"CreationDate": "2019-09-26T19:46:52.285871Z", | |
"LastEditor": "jm", | |
"LanguageName": "Csharp", | |
"CodeBlock": "int Square(int x) =\u003e (int)Math.Pow(x, 2);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.microsoft.com/dotnet/api/system.math.pow", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:46:52.285871Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3091, | |
"OrigId": 3091, | |
"Author": "Jurassic", | |
"CreationDate": "2019-09-26T20:43:40.363406Z", | |
"LastEditor": "Jurassic", | |
"LanguageName": "JS", | |
"CodeBlock": "const square = (number) =\u003e Math.pow(number, 2);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:43:40.363406Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3116, | |
"OrigId": 3116, | |
"Author": "gumbo59", | |
"CreationDate": "2019-09-26T21:51:35.923551Z", | |
"LastEditor": "gumbo59", | |
"LanguageName": "JS", | |
"CodeBlock": "const numToBeSquared = 4;\n\nconst squaredNum = numToBeSquared ** 2;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "** is the exponentiation operator and is useful for quick powers. For square, we're just calling the numToBeSquared to the 2nd power.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T21:56:27.354142Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3362, | |
"OrigId": 3362, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:14:09.284354Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Public Function Square(x As Integer) As Double\n Return x * 2\nEnd Function", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:14:09.284354Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 38, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 5, | |
"OrigId": 0, | |
"Title": "Create a 2D Point data structure", | |
"LeadParagraph": "Declare a container type for two floating-point numbers _x and _y", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Fortran] Kind definition obscures the purpose of the example, and integer literals are not portable among compilers.", | |
"LastEditedImplID": 1382, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/5/2D_point.png", | |
"Version": 384, | |
"VersionDate": "2019-09-28T05:54:31.010948Z", | |
"Implementations": [ | |
{ | |
"Id": 27, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "", | |
"LanguageName": "Java", | |
"CodeBlock": "class Point{\n double x;\n double y;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 29, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "type Point struct {\n x, y float64\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/CkmxNoBejE", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 30, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "", | |
"LanguageName": "C", | |
"CodeBlock": "typedef struct {\n double x;\n double y;\n} Point;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 73, | |
"OrigId": 73, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "Chops", | |
"LanguageName": "Cpp", | |
"CodeBlock": "struct Point{\n double x;\n double y;\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T14:21:55.608883Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 74, | |
"OrigId": 74, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "Chops", | |
"LanguageName": "Cpp", | |
"CodeBlock": "struct Point{\n double x;\n double y;\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T14:21:14.572538Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 89, | |
"OrigId": 89, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "Point = Struct.new(:x, :y)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.ruby-doc.org/core-2.1.0/Struct.html", | |
"AuthorComment": "Instantiate like this : Point.new(1.0,1.0)", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 98, | |
"OrigId": 98, | |
"Author": "Tcha", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var p = { x: 1.122, y: 7.45 };", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Types are implicit. Just initialize a variable. ", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 296, | |
"OrigId": 296, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $point = [ 1.5, 6.3 ];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This array uses indices 0, 1 to hold _x, _y.\r\n\r\nNo need to declare a type beforehand.\r\n\r\nFor lists, perl prefers using arrays (over using hashes).", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 424, | |
"OrigId": 424, | |
"Author": "fbstj", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "fbstj", | |
"LanguageName": "Rust", | |
"CodeBlock": "struct Point { x: f64, y: f64, }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 529, | |
"OrigId": 529, | |
"Author": "wobbles", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "struct Point{\n double x;\n double y;\n}\n\n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Structs are value types.", | |
"Version": 2, | |
"VersionDate": "2017-07-29T23:22:02.779971Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 608, | |
"OrigId": 608, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "class Point {\n double x, y;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 619, | |
"OrigId": 619, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "foo", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $point = { x =\u003e 1, y =\u003e 2 };", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "In a hash, members are named.\r\n\r\nNo need to declare a type beforehand.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T19:54:21.760558Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 651, | |
"OrigId": 651, | |
"Author": "flappertapper", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "flappertapper", | |
"LanguageName": "Pascal", | |
"CodeBlock": "Type\n TPoint = Record\n x : Double;\n y : Double;\n End;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Pascal uses unit math to define type float.\r\n\r\nYou can use one of Pascal's floating point types directly (being type single or type double), depending on which precision is required.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 663, | |
"OrigId": 663, | |
"Author": "cym13", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "surfloede", | |
"LanguageName": "Python", | |
"CodeBlock": "@dataclass\nclass Point:\n x: float\n y: float", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/3/library/dataclasses.html", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T14:09:14.093527Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "from dataclasses import dataclass", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 711, | |
"OrigId": 711, | |
"Author": "lrhn", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "lrhn", | |
"LanguageName": "Dart", | |
"CodeBlock": "class Point {\n double x, y;\n Point(this.x, this.y);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "With constructor, which you will almost always have.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 785, | |
"OrigId": 785, | |
"Author": "nsmryan", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "nsmryan", | |
"LanguageName": "Haskell", | |
"CodeBlock": "data Point = Point \n { x :: Double\n , y :: Double \n }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 791, | |
"OrigId": 791, | |
"Author": "nsmryan", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "Haskell", | |
"CodeBlock": "data Point = Point\n { x :: Double\n , y :: Double\n } deriving (Eq, Ord, Show, Read)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This version contains a deriving statement at the end which automatically writes the equality, ordering, and to and from string functions for this type.", | |
"Version": 2, | |
"VersionDate": "2019-09-27T10:11:38.685529Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 810, | |
"OrigId": 810, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "[x y]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojure.org/data_structures#Data Structures-Vectors (IPersistentVector)", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 939, | |
"OrigId": 939, | |
"Author": "anandubajith", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "p = [ x: 1.122, y: 7.45 ]\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/b70e2b371d", | |
"DocumentationURL": "http://elixir-lang.org/getting-started/maps-and-dicts.html#keyword-lists", | |
"AuthorComment": "Just create values with appropriate keys.", | |
"Version": 2, | |
"VersionDate": "2017-02-07T22:13:40.356602Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1115, | |
"OrigId": 1115, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-module(points).\n-export([new/2, x/1, y/1]).\n\n-opaque point() :: #{x =\u003e float(), y =\u003e float()}.\n-export_type([point/0]).\n\n-spec new(float(), float()) -\u003e point().\nnew(X, Y) -\u003e #{x =\u003e X, y =\u003e Y}.\n\n-spec x(point()) -\u003e float().\nx(#{x := X}) -\u003e X.\n\n-spec y(point()) -\u003e float().\ny(#{y := Y}) -\u003e Y.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "to use this module from somewhere else you do stuff like...\r\n_Point = points:new(_X, _Y),\r\n_X = points:x(_Point),\r\n_Y = points:y(_Point).", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1116, | |
"OrigId": 1116, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "PointAsAMap = #{x =\u003e X, y =\u003e Y}.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1117, | |
"OrigId": 1117, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "PointAsATuple = {X, Y}.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1272, | |
"OrigId": 1272, | |
"Author": "dhe", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "dhe", | |
"LanguageName": "Csharp", | |
"CodeBlock": "struct Point\n {\n public double x;\n public double y;\n };", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1288, | |
"OrigId": 1288, | |
"Author": "djxfade", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "class Point\n{\n /** @var float */\n public $x = 0.0;\n\n /** @var float */\n public $y = 0.0;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T22:10:25.184897Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1293, | |
"OrigId": 1293, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "point = { x = 123, y = 456 }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1298, | |
"OrigId": 1298, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "type Point is\n record\n X : Float;\n Y : Float;\n end record;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1332, | |
"OrigId": 1332, | |
"Author": "LukaJCB", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "LukaJCB", | |
"LanguageName": "Scala", | |
"CodeBlock": "case class Point(x: Float, y: Float)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:55.615021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1382, | |
"OrigId": 1382, | |
"Author": "Paul_Dirac", | |
"CreationDate": "2016-02-18T16:57:55.615021Z", | |
"LastEditor": "pompito", | |
"LanguageName": "Fortran", | |
"CodeBlock": "type point\n real :: x\n real :: y\nend type point", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-28T05:54:31.00517Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2011, | |
"OrigId": 2011, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-06T15:09:03.420895Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (make-point x y)\n (cons x y))\n(define (point-x p)\n (car p))\n(define (point-y p)\n (cdr p))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-06-06T15:14:10.694244Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2054, | |
"OrigId": 2054, | |
"Author": "Meta", | |
"CreationDate": "2017-07-26T00:45:10.582374Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "class Point\n{\n float x;\n float y;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Classes are reference types.", | |
"Version": 2, | |
"VersionDate": "2017-07-29T23:22:52.450443Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2715, | |
"OrigId": 2715, | |
"Author": "r_p4rk", | |
"CreationDate": "2019-09-26T13:58:01.956686Z", | |
"LastEditor": "r_p4rk", | |
"LanguageName": "JS", | |
"CodeBlock": "const point = { x: 1, y: 2 };", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T13:58:01.956686Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2721, | |
"OrigId": 2721, | |
"Author": "lab419", | |
"CreationDate": "2019-09-26T14:02:55.848681Z", | |
"LastEditor": "lab419", | |
"LanguageName": "Elixir", | |
"CodeBlock": "{x, y}\ndefmodule Point do\n defstruct x: 0.0, y: 0.0\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "the tuple does the trick but a type is best implemented by a struct which is a module\r\n_N.B. the types of _x and _y can change", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:02:55.848681Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2855, | |
"OrigId": 2855, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:08:53.372441Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defstruct point\n (x 0.0d0 :type double-float)\n (y 0.0d0 :type double-float))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:08:53.372441Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2883, | |
"OrigId": 2883, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:43:05.316748Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "type point = {\n\tx: float;\n\ty: float;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:43:32.152165Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2907, | |
"OrigId": 2907, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:55:06.223899Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "module x\n type point\n real :: x, y\n end type point\nend module x\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:55:06.223899Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2963, | |
"OrigId": 2963, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:34:58.184Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "data class Point(val x: Float, val y: Float)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:35:49.236373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3363, | |
"OrigId": 3363, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:16:12.679329Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Public Class Point\n Public x As Single\n Public y As Single\nEnd Class", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:16:12.679329Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 37, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 6, | |
"OrigId": 0, | |
"Title": "Iterate over list values", | |
"LeadParagraph": "Do something with each item _x of an array-like collection _items, regardless indexes.", | |
"ExtraKeywords": "foreach traverse traversal", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Cobol] fix", | |
"LastEditedImplID": 3422, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 80, | |
"VersionDate": "2019-09-28T11:59:38.822226Z", | |
"Implementations": [ | |
{ | |
"Id": 31, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "for(Item x : items ){\n\tdoSomething( x );\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This syntax is allowed since Java 5.\r\nIt works with arrays or collections as well.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 32, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "", | |
"LanguageName": "Python", | |
"CodeBlock": "for x in items:\n doSomething( x )", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 33, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "for _, x := range items {\r\n doSomething( x )\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "You have to explicitly ignore the index loop variable, with the blank identifier _", | |
"Version": 2, | |
"VersionDate": "2016-04-14T12:30:56.881425Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 53, | |
"OrigId": 53, | |
"Author": "Otakode", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "for (unsigned int i = 0 ; i \u003c items_length ; ++i){\n Item* x = \u0026(items[i]);\n\tDoSomethingWith(x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_items_length type is: _unsigned _int\r\n_DoSomethingWith prototype is: void DoSomethingWith(Item*);", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 64, | |
"OrigId": 64, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.each{|x| do_something( x )}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-04-14T11:17:30.105695Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 103, | |
"OrigId": 103, | |
"Author": "Tcha", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "items.forEach((x) =\u003e {\n doSomething(x);\n});", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2019-09-26T18:02:52.755608Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 104, | |
"OrigId": 104, | |
"Author": "Tcha", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "for (x of items) {\n\tdoSomething(x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T18:03:17.439801Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 152, | |
"OrigId": 152, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (doSomething x)\n (if (not (null? x))\n (begin \n (display \"Item=\")\n (display (car x))\n (newline)\n (doSomething (cdr x)))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://repl.it/SIK", | |
"DocumentationURL": "", | |
"AuthorComment": "Iteration is achieved by recursion.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 153, | |
"OrigId": 153, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "for(int i=0;i\u003citems.length;i++){\n\tdoSomething( items[i] );\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This syntax is now \"old-school\" since the foreach construct introduced in Java 5.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 201, | |
"OrigId": 201, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "Nick", | |
"LanguageName": "Dart", | |
"CodeBlock": "items.forEach(doSomething);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://www.dartlang.org/docs/dart-up-and-running/ch02.html#functions-as-first-class-objects", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-02-18T08:19:14.283543Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 235, | |
"OrigId": 235, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "foreach ($items as $x){\n doSomething( $x );\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/control-structures.foreach.php", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 289, | |
"OrigId": 289, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "do_something($_) for @items;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This performs a single operation on each element", | |
"Version": 2, | |
"VersionDate": "2016-06-05T18:11:15.924101Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 407, | |
"OrigId": 407, | |
"Author": "Stebalien", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "for x in items {\n\tdo_something(x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 510, | |
"OrigId": 510, | |
"Author": "bbtemp", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "bbtemp", | |
"LanguageName": "D", | |
"CodeBlock": "foreach(x; items) {\n\tdoSomethingWith(x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 653, | |
"OrigId": 653, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "for x in items do ;", | |
"OriginalAttributionURL": "http://www.programming-idioms.org/idiom/6/impl/513", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 805, | |
"OrigId": 805, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "JH", | |
"LanguageName": "Haskell", | |
"CodeBlock": "forM_ items doSomething\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-02-16T17:52:56.259271Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Control.Monad", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 818, | |
"OrigId": 818, | |
"Author": "jfacorro", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(map do-something items)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/map", | |
"AuthorComment": "_do-_something should be a function that receives a single argument. _map returns a lazy seq, which means the function _do-_something won't be applied until the results are needed.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 922, | |
"OrigId": 922, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Enum.each(items, \u0026IO.inspect/1)\n\nfor x \u003c- items do\n IO.inspect(x)\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/e96f77f978", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/Enum.html#each/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1113, | |
"OrigId": 1113, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "[do_something(X) || X \u003c- Items]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.erlang.org/doc/programming_examples/list_comprehensions.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1114, | |
"OrigId": 1114, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:24.664036Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "lists:foreach(fun do_something/1, Items).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=0\u0026search=lists:for#foreach/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:24.664036Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1277, | |
"OrigId": 1277, | |
"Author": "usadamasa", | |
"CreationDate": "2016-02-10T02:31:49.924022Z", | |
"LastEditor": "jdashg", | |
"LanguageName": "Cpp", | |
"CodeBlock": "for(const auto \u0026x : items) {\n\tdoSomething(x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/language/range-for", | |
"AuthorComment": "This \"range-based for loop\" exists since C++11.", | |
"Version": 3, | |
"VersionDate": "2019-09-26T19:32:00.052237Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1292, | |
"OrigId": 1292, | |
"Author": "HarrisJ", | |
"CreationDate": "2016-02-16T14:07:00.775188Z", | |
"LastEditor": "HarrisJ", | |
"LanguageName": "Csharp", | |
"CodeBlock": "foreach(var item in items)\r\n{\r\n\tdoSomething(item);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://msdn.microsoft.com/en-us/library/ttw7t8t6.aspx", | |
"AuthorComment": "var can be replaced with the type of the item", | |
"Version": 1, | |
"VersionDate": "2016-02-16T14:07:00.775188Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1296, | |
"OrigId": 1296, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T15:02:59.945792Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "for _, x in ipairs(items) do\r\n\tprint(x)\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T15:02:59.945792Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1299, | |
"OrigId": 1299, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-16T15:10:30.251279Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "for Item of Items loop\r\n Do_Something (Item);\r\nend loop;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T15:10:30.251279Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1334, | |
"OrigId": 1334, | |
"Author": "LukaJCB", | |
"CreationDate": "2016-02-16T16:50:56.124973Z", | |
"LastEditor": "LukaJCB", | |
"LanguageName": "Scala", | |
"CodeBlock": "for (item \u003c- items) doSomething(item)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:50:56.124973Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1696, | |
"OrigId": 1696, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-04-14T11:16:06.854283Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.each do |x|\r\n do_something( x )\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-14T11:16:06.854283Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1735, | |
"OrigId": 1735, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-06-05T18:10:09.749519Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "for my $x (@items) {\r\n do_something($x);\r\n more_stuffs($x);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This construct is best for multiple operations on _$x", | |
"Version": 1, | |
"VersionDate": "2016-06-05T18:10:09.749519Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1775, | |
"OrigId": 1775, | |
"Author": "BBaz", | |
"CreationDate": "2016-08-13T21:50:46.419963Z", | |
"LastEditor": "BBaz", | |
"LanguageName": "D", | |
"CodeBlock": "items.each!(a =\u003e writeln(a))();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://dlang.org/phobos/std_algorithm_iteration.html#.each", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-08-13T21:50:54.360012Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm.iteration;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2794, | |
"OrigId": 2794, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:15:57.763955Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(map nil #'something items)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:15:57.763955Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2854, | |
"OrigId": 2854, | |
"Author": "Jaimie", | |
"CreationDate": "2019-09-26T16:07:50.694585Z", | |
"LastEditor": "Jaimie", | |
"LanguageName": "Java", | |
"CodeBlock": "items.stream().forEach(item -\u003e doSomething(item));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This syntax uses the streams api introduced in Java 8.\r\n", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:07:50.694585Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2886, | |
"OrigId": 2886, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:44:48.196321Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "items |\u003e List.iter do_something", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:45:13.392023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2971, | |
"OrigId": 2971, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:41:31.407178Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "items.forEach { doSomething(it) }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:42:02.400347Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2975, | |
"OrigId": 2975, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:44:15.486527Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "items.forEach(::doSomething)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Using a function reference.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:44:15.486527Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2993, | |
"OrigId": 2993, | |
"Author": "munk-a", | |
"CreationDate": "2019-09-26T18:00:32.9843Z", | |
"LastEditor": "munk-a", | |
"LanguageName": "PHP", | |
"CodeBlock": "array_map(func, $items);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/Tuts2", | |
"DocumentationURL": "", | |
"AuthorComment": "Function does need to be a real function and not a language construct, so you can't directly map _- (the unary negation operator) or other function like constructs like _echo or _print\r\n\r\nDo note, this fails for iteratable non-arrays, the _foreach based approach is better in that situation.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:01:38.35458Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3045, | |
"OrigId": 3045, | |
"Author": "Jeff McMahan", | |
"CreationDate": "2019-09-26T19:41:53.910898Z", | |
"LastEditor": "Jeff McMahan", | |
"LanguageName": "JS", | |
"CodeBlock": "items.forEach(doSomething)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach", | |
"AuthorComment": "No need to create another anonymous function; just pass a function directly to .forEach.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:41:53.910898Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3285, | |
"OrigId": 3285, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T16:44:47.890372Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "elemental subroutine foo(x)\n real, intent(in) :: x\nend subroutine foo\n\ncall foo(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T16:44:47.890372Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3300, | |
"OrigId": 3300, | |
"Author": "phrank", | |
"CreationDate": "2019-09-27T19:16:05.491126Z", | |
"LastEditor": "phrank", | |
"LanguageName": "C", | |
"CodeBlock": "for (size_t i = 0; i \u003c sizeof(items) / sizeof(items[0]); i++) {\n\tDoSomethingWith(\u0026items[i]);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_sizeof the array divided by the size of the first element computes the number of elements, often defined as macro _ARRAY_SIZE", | |
"Version": 1, | |
"VersionDate": "2019-09-27T19:16:05.491126Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3305, | |
"OrigId": 3305, | |
"Author": "mb", | |
"CreationDate": "2019-09-27T19:49:41.775463Z", | |
"LastEditor": "mb", | |
"LanguageName": "Csharp", | |
"CodeBlock": "foreach (var item in items) \n{\n DoSomething(item);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T19:49:41.775463Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3358, | |
"OrigId": 3358, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:11:15.54208Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Dim ItemList As New List(Of String)(New String() {\"one\", \"two\", \"three\"})\nFor Each item In ItemList\n Console.WriteLine(item)\nNext", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:11:15.54208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3422, | |
"OrigId": 3422, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-28T11:59:18.483756Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. list.\nDATA DIVISION.\nWORKING-STORAGE SECTION.\n01 LIST.\n 03 X OCCURS 5 TIMES\n INDEXED BY i PIC 9.\nPROCEDURE DIVISION. \n PERFORM VARYING i FROM 1 BY 1 UNTIL i \u003e 5\n DISPLAY X(i)\n END-PERFORM \nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-28T11:59:38.81864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 40, | |
"Rating": 1, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
7, | |
134, | |
163 | |
], | |
"RelatedIdiomTitles": [ | |
"Iterate over list indexes and values", | |
"Create a new list", | |
"Print list elements by group of 2" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 7, | |
"OrigId": 0, | |
"Title": "Iterate over list indexes and values", | |
"LeadParagraph": "Print each index _i with its value _x from an array-like collection _items", | |
"ExtraKeywords": "traverse traversal", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New VB implementation by user [EvilGenius]", | |
"LastEditedImplID": 3369, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 76, | |
"VersionDate": "2019-09-27T23:24:32.639016Z", | |
"Implementations": [ | |
{ | |
"Id": 34, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "for i, x := range items {\r\n fmt.Printf(\"Item %d = %v \\n\", i, x)\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/GH_8f06DX5", | |
"DocumentationURL": "https://golang.org/doc/effective_go.html#for", | |
"AuthorComment": "The range clause gives you index _i and value _x at the same time as loop variables", | |
"Version": 2, | |
"VersionDate": "2016-06-05T16:53:12.402597Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"fmt\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 35, | |
"OrigId": 0, | |
"Author": "", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "int i;\nfor(i=0 ; i\u003cn ; i++){\n T x = items[i];\n printf(\"Item %d = %s\\n\", i, toString(x) );\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The loop variable i is the index. Inside the loop, access the value with _items[_i]", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 96, | |
"OrigId": 96, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.each_with_index do |x, i| \n puts \"Item #{i} = #{x}\"\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "See also the one-liner Ruby solution", | |
"Version": 3, | |
"VersionDate": "2017-04-17T18:51:49.140693Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 97, | |
"OrigId": 97, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.each_index{|i| puts \"Item %d = %s\" % [i, items[i]]}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2017-04-17T18:51:17.931035Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 183, | |
"OrigId": 183, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "for i, x in enumerate(items):\n print i, x", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/522563/accessing-the-index-in-python-for-loops", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 300, | |
"OrigId": 300, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "# For an array\nwhile ( ($idx, $val) = each @array) {\n print \"array[$i] = $val\\n\";\n}\n\n# For a hash\nwhile ( ($key, $val) = each %hash) {\n print \"hash{$key} = $val\\n\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The each iterator returns the index/key and value as a pair for each iteration.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 358, | |
"OrigId": 358, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "items.forEach((val, idx) =\u003e {\n console.log(\"index=\" + idx + \", value=\" + val);\n});", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This is the functional way of iterating.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:00:39.283266Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 394, | |
"OrigId": 394, | |
"Author": "christianhujer", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "christianhujer", | |
"LanguageName": "Java", | |
"CodeBlock": "for (int i = 0; i \u003c items.length; i++) {\n T x = items[i];\n System.out.printf(\"Item %d = %s%n\", i, x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Solution if the list is an array.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 395, | |
"OrigId": 395, | |
"Author": "christianhujer", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "christianhujer", | |
"LanguageName": "Java", | |
"CodeBlock": "for (int i = 0; i \u003c items.size(); i++) {\n T x = items.get(i);\n System.out.printf(\"Item %d = %s%n\", i, x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Solution if the list is a List.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 415, | |
"OrigId": 415, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "for (i, x) in items.iter().enumerate() {\n println!(\"Item {} = {}\", i, x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 462, | |
"OrigId": 462, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "foreach ($items as $i=\u003e$x)\n{\n echo \"i=$i, x=$x\"; echo '\u003cbr\u003e';\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 521, | |
"OrigId": 521, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "schveiguy", | |
"LanguageName": "D", | |
"CodeBlock": "foreach(i, x; items)\n{\n writefln(\"%s: %s\", i, x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "use 'ref' on the item variable 'x' to access by reference", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 592, | |
"OrigId": 592, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var I:Integer;\r\n Items: array of String;\r\n[..]\r\n for I := 0 to high(Items) do\r\n WriteLn('Item ', I, ' = ', Items[I]);\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-27T22:20:09.024082Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 593, | |
"OrigId": 593, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var I:Integer;\r\n Items: array of TObject;\r\n[...]\r\n for I := 0 to high(Items) do\r\n if assigned(Items[I]) then\r\n WriteLn(Format('Item %d = %s', [I, Items[I].ToString]));\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "If you have an _TObjects descendent, you can use the _ToString method to get it as a String.\r\n", | |
"Version": 2, | |
"VersionDate": "2016-11-27T22:19:25.701872Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "Classes, SysUtils", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 601, | |
"OrigId": 601, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "for (var i = 0; i \u003c items.length; i++) {\n print('index=$i, value=${items[i]}');\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/76313789b417c557a0ad", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 712, | |
"OrigId": 712, | |
"Author": "lrhn", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "lrhn", | |
"LanguageName": "Dart", | |
"CodeBlock": "items.asMap().forEach((i, value) {\n print('index=$i, value=$value');\n});", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "An alternative, but not really idiomatic.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 801, | |
"OrigId": 801, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "ara", | |
"LanguageName": "Haskell", | |
"CodeBlock": "mapM_ print (zip [0..] items)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 806, | |
"OrigId": 806, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "finalfantasia", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(doseq [[i x] (map-indexed vector items)]\n (println i \":\" x))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/map-indexed", | |
"AuthorComment": "_items can be any Clojure collection (vector, list, set, map). We construct a new sequence which contains in each element the index of each one and its original value in _items. _doseq is used for side-effects.\t", | |
"Version": 5, | |
"VersionDate": "2019-09-26T18:36:35.046342Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 920, | |
"OrigId": 920, | |
"Author": "ventsislaf", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "items\n|\u003e Enum.with_index\n|\u003e Enum.each(fn({x, i}) -\u003e\n IO.puts(\"#{i} =\u003e #{x}\")\nend)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/f971142f9a", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/Enum.html#with_index/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1065, | |
"OrigId": 1065, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "WithIndex =\n lists:zip(lists:seq(1, length(Items)), Items),\nio:format(\"~p~n\", [WithIndex]).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=2ef3", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=0\u0026search=lists:zip#zip/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1247, | |
"OrigId": 1247, | |
"Author": "mikee", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "rpm", | |
"LanguageName": "Cpp", | |
"CodeBlock": "for(const auto \u0026 item : items) {\n static auto idx = 0;\n std::cout \u003c\u003c \"Item \" \u003c\u003c idx++ \u003c\u003c \" = \" \u003c\u003c item \u003c\u003c std::endl;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/language/range-for", | |
"AuthorComment": "Uses the C++11 features \"range based for loop\" and \"auto\". Index is initialized to zero only once for the entire program regardless of how many times this loop is run. Also not thread safe.", | |
"Version": 3, | |
"VersionDate": "2019-09-26T14:56:49.369907Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e\r\n#include \u003cvector\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1267, | |
"OrigId": 1267, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "for (var i in items) {\n console.log(\"index=\" + i + \", value=\" + items[i]);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "this is a horrible implementation, use the \"functional\" one above. If you don't need the index, using \"for...of\" is ok, \"for...in\" almost never is.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:01:57.191646Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1271, | |
"OrigId": 1271, | |
"Author": "dhe", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "for (int i = 0; i \u003c items.Length; i++)\n{\n Console.WriteLine(\"{0} {1}\", i, items[i]);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1295, | |
"OrigId": 1295, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "for i, x in ipairs(items) do\n\tprint('Index: '..i..', Value: '..x)\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1307, | |
"OrigId": 1307, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "for I in Items'Range loop\n X := Items (I);\n Put_Line (Integer'Image (I) \u0026 \" \" \u0026 Integer'Image (X));\nend loop;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Assuming _Items is an array of integers.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Text_IO;\r\nuse Ada.Text_IO;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1428, | |
"OrigId": 1428, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:56.046799Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val items = List(\"a\", \"b\", \"c\")\nitems.zipWithIndex.foreach{ case (item, index) =\u003e \n println(s\"$index =\u003e $item\")\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "zipWithIndex takes each _item in a collection and replaces it with a tuple of (_item, _index)", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.046799Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2016, | |
"OrigId": 2016, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-07T15:45:20.700012Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (display-list items)\n (define (display-list items i)\n (if (not (null? items))\n (begin\n (display (string-append\n (number-\u003estring i)\n \": \"\n (number-\u003estring (first items))\n \"\\n\"))\n (display-list (rest items) (+ i 1)))\n 'done))\n (display-list items 0))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Iteration is tail-recursion.", | |
"Version": 1, | |
"VersionDate": "2017-06-07T15:45:20.700012Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2063, | |
"OrigId": 2063, | |
"Author": "Bzzzzzzz", | |
"CreationDate": "2017-07-27T23:58:21.277831Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "items.enumerate.each!(a =\u003e writeln(\"i = \", a[0], \" value = \", a[1]));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/XSUx64", | |
"DocumentationURL": "https://dlang.org/phobos/std_range.html#enumerate", | |
"AuthorComment": "_enumerate can be used instead of _foreach with an index when the statement is simple enough to be a lambda or when the _foreach _aggregate (the array like thing) can't be indexed.", | |
"Version": 2, | |
"VersionDate": "2017-07-30T16:13:03.291737Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio, std.algorithm;\r\nimport std.range;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2749, | |
"OrigId": 2749, | |
"Author": "no", | |
"CreationDate": "2019-09-26T14:35:42.72707Z", | |
"LastEditor": "no", | |
"LanguageName": "Cpp", | |
"CodeBlock": "for (std::size_t ix = 0; ix \u003c items.size(); ++ix) {\n std::cout \u003c\u003c \"Item \" \u003c\u003c ix \u003c\u003c \" = \" \u003c\u003c items[ix] \u003c\u003c std::endl;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:35:42.72707Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2784, | |
"OrigId": 2784, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:06:45.743996Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(loop for i from 0 and x across items\n do (format t \"~a = ~a~%\" i x))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:06:45.743996Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2896, | |
"OrigId": 2896, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:49:33.349412Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "(* output_elem is a printer for elements of [items] *)\nitems |\u003e List.iteri (fun i x -\u003e\n\tprintf \"%d: %a\" i output_elem x\n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:49:33.349412Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2979, | |
"OrigId": 2979, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:49:40.260039Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "items.withIndex().forEach { (i, x) -\u003e \n print(\"i=$i x=$x\") \n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:49:40.260039Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3046, | |
"OrigId": 3046, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T19:42:07.33135Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "do i=1, size(items)\n print *,i, items(i)\nend do", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:42:07.33135Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3369, | |
"OrigId": 3369, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:24:32.634803Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Dim ItemList As New List(Of String)(New String() {\"one\", \"two\", \"three\"})\nFor x = 0 To ItemList.Count - 1\n Console.WriteLine(x \u0026 \" \" \u0026 ItemList(x))\nNext", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:24:32.634803Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 34, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
6, | |
134 | |
], | |
"RelatedIdiomTitles": [ | |
"Iterate over list values", | |
"Create a new list" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 8, | |
"OrigId": 0, | |
"Title": "Initialize a new map (associative array)", | |
"LeadParagraph": "Declare a new map object _x, and provide some (key, value) pairs as initial content.", | |
"ExtraKeywords": "table dictionary hash", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New C implementation by user [phrank]", | |
"LastEditedImplID": 3301, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 59, | |
"VersionDate": "2019-09-27T19:28:17.566559Z", | |
"Implementations": [ | |
{ | |
"Id": 38, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "x := map[string]int {\"one\": 1, \"two\": 2}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/P9yxcWDubV", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2018-12-30T11:42:43.442333Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 39, | |
"OrigId": 39, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": ".", | |
"LanguageName": "Python", | |
"CodeBlock": "x = {\"one\" : 1, \"two\" : 2}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/PeXCe1", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-03-20T06:42:48.892383Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 40, | |
"OrigId": 40, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms", | |
"LanguageName": "Java", | |
"CodeBlock": "Map\u003cString,Integer\u003e x = new HashMap\u003c\u003e();\nx.put(\"one\", 1);\nx.put(\"two\", 2);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/iq8mh4", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Map;\r\nimport java.util.HashMap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 56, | |
"OrigId": 56, | |
"Author": "Otakode", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::map\u003cconst char*, int\u003e x;\nx[\"one\"] = 1;\nx[\"two\"] = 2;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.cplusplus.com/reference/map/map/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cmap\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 65, | |
"OrigId": 65, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x = {one: 1, two: 2}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/E9q9/0", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-11-28T22:30:24.238284Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 82, | |
"OrigId": 82, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "const x = {one: 1, two:2}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "An object in JavaScript is essentially an associative array", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:47:16.256363Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 155, | |
"OrigId": 155, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define x '(\n (\"one\" 1) \n (\"two\" 2) \n (\"three\" 3)))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://repl.it/SIU/1", | |
"DocumentationURL": "", | |
"AuthorComment": "Warning : the built-in association lists are inefficient, so don't use them for large data sets.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 202, | |
"OrigId": 202, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var x = {\n\t\"one\": 1,\n\t\"two\": 2\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://www.dartlang.org/docs/dart-up-and-running/contents/ch03.html#ch03-maps-aka-dictionaries-or-hashes", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 237, | |
"OrigId": 237, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "$x = ['one' =\u003e 1, 'two' =\u003e 2];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/language.types.array.php", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:32:17.668782Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 292, | |
"OrigId": 292, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my %map = ( \n name=\u003e'Roboticus',\n \"foo bar\"=\u003e\"joe\"\n);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The '=\u003e' operator turns the left side item into a string, so you don't need to quote the value unless it has spaces or other special characters in it.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 419, | |
"OrigId": 419, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let mut x = BTreeMap::new();\nx.insert(\"one\", 1);\nx.insert(\"two\", 2);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2015\u0026gist=9186f79202d93bc33b1558428c40da93", | |
"DocumentationURL": "", | |
"AuthorComment": "Something different than a _BTreeMap might be used, depending on the usage.\r\n\r\nThe function _new of the type _BTreeMap returns a usable map.\r\nThe map is stored mutable in the variable _x.\r\n\r\nMaps in Rust are generic but the type is determined by the compiler based on the later usage.\r\nA line such as `x.insert(1, \"one\")` would therefore not compile.", | |
"Version": 3, | |
"VersionDate": "2018-12-30T11:40:42.821658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::collections::BTreeMap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 523, | |
"OrigId": 523, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "schveiguy", | |
"LanguageName": "D", | |
"CodeBlock": "int[string] x = [\"one\": 1, \"two\": 2];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Could also use 'auto' for x's type, as associative array literal syntax defines its type.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 753, | |
"OrigId": 753, | |
"Author": "Geep Jeez", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "Geep Jeez", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type TMap = specialize TFPGMap\u003cString, Integer\u003e;\nvar x: TMap;\n\nbegin\n x := TMap.Create;\n x['one'] := 1;\n x['two'] := 2; \nend.\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://wiki.freepascal.org/Generics#fgl_unit", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses fgl;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 821, | |
"OrigId": 821, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "schuelermine", | |
"LanguageName": "Haskell", | |
"CodeBlock": "x = Data.Map.Strict.fromList [ (\"red\", \"FF0000\"), (\"blue\", \"0000FF\") ]\n\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/containers/docs/Data-Map-Strict.html", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-06-07T10:26:12.54797Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Data.Map.Strict", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 896, | |
"OrigId": 896, | |
"Author": "rrrene", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "x = %{\"one\" =\u003e 1, \"two\" =\u003e 2}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/16a47e1f62", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T21:41:48.310741Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1120, | |
"OrigId": 1120, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "X = #{one =\u003e 1, \"two\" =\u003e 2.0, \u003c\u003c\"three\"\u003e\u003e =\u003e [i, i, i]}.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.erlang.org/doc/man/maps.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1325, | |
"OrigId": 1325, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "x = {one = 1, two = 2}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1350, | |
"OrigId": 1350, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "declare\n package Maps is new Indefinite_Hashed_Maps (Key_Type =\u003e String,\n Element_Type =\u003e Integer,\n Hash =\u003e Ada.Strings.Hash,\n Equivalent_Keys =\u003e \"=\");\n \n use Maps;\n \n X : Map := Empty_Map;\nbegin\n X.Insert (\"One\", 1);\n X.Insert (\"Two\", 2);\n X.Insert (\"Three\", 3);\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Containers.Indefinite_Hashed_Maps;\r\nwith Ada.Strings.Hash;\r\n\r\nuse Ada.Containers;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1356, | |
"OrigId": 1356, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Dictionary\u003cint, string\u003e x = new Dictionary\u003cint, string\u003e()\n{\n (1, \"Value1\"),\n (2, \"Value2\")\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx", | |
"AuthorComment": "Example uses collection initializer. To add manually, use:\r\n\r\n_x._Add(_1, \"_Value1\");", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "System.Collections.Generic", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1443, | |
"OrigId": 1443, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:56.147637Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val x = Map(\"a\" -\u003e 1, \"b\" -\u003e 2, \"c\" -\u003e 3)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.147637Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2100, | |
"OrigId": 2100, | |
"Author": "Jerry", | |
"CreationDate": "2017-09-01T14:00:06.861078Z", | |
"LastEditor": "Jerry", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(def x {\"One\" 1\n\t\"Two\" 2\n\t\"Three\" 3})", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "(get x \"Two\") will then return 2", | |
"Version": 1, | |
"VersionDate": "2017-09-01T14:00:06.861078Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2470, | |
"OrigId": 2470, | |
"Author": "freecoder", | |
"CreationDate": "2018-12-17T18:13:14.571272Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "let x: HashMap\u003c\u0026str, i32\u003e = [\n (\"one\", 1),\n (\"two\", 2),\n].iter().cloned().collect();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2018\u0026gist=a4894d64bd00f4122fb7abdb7189cb09", | |
"DocumentationURL": "https://doc.rust-lang.org/std/collections/struct.HashMap.html", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-12-17T18:14:33.01779Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::collections::HashMap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2774, | |
"OrigId": 2774, | |
"Author": "yuchi", | |
"CreationDate": "2019-09-26T14:56:39.318882Z", | |
"LastEditor": "yuchi", | |
"LanguageName": "JS", | |
"CodeBlock": "const x = new Map();\nx.set(\"one\", 1);\nx.set(\"two\", 2);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map", | |
"AuthorComment": "From ES2015", | |
"Version": 3, | |
"VersionDate": "2019-09-26T14:58:39.225293Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3031, | |
"OrigId": 3031, | |
"Author": "testing", | |
"CreationDate": "2019-09-26T19:18:36.926315Z", | |
"LastEditor": "testing", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::unordered_map\u003cstd::string, double\u003e mymap = {\n {\"mom\", 5.4},\n {\"dad\", 6.1},\n {\"bro\", 5.9}\n};", | |
"OriginalAttributionURL": "http://www.cplusplus.com/reference/unordered_map/unordered_map/find/", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.cplusplus.com/reference/unordered_map/unordered_map/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:18:36.926315Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cunordered_map\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3038, | |
"OrigId": 3038, | |
"Author": "scott_s", | |
"CreationDate": "2019-09-26T19:36:58.429282Z", | |
"LastEditor": "scott_s", | |
"LanguageName": "Java", | |
"CodeBlock": "final Map\u003cString, Integer\u003e x = new HashMap\u003cString, Integer\u003e() {{\n put(\"one\", 1);\n put(\"two\", 2);\n put(\"three\", 3);\n}};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:36:58.429282Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Map;\r\nimport java.util.HashMap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3057, | |
"OrigId": 3057, | |
"Author": "javajosh", | |
"CreationDate": "2019-09-26T19:49:53.022608Z", | |
"LastEditor": "javajosh", | |
"LanguageName": "JS", | |
"CodeBlock": "const x = new Map([[\"one\",1],[\"two\",2]]);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map", | |
"AuthorComment": "The Map constructor can take an array of [key, value] pairs.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T19:50:46.871275Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3108, | |
"OrigId": 3108, | |
"Author": "roryg", | |
"CreationDate": "2019-09-26T21:39:15.509783Z", | |
"LastEditor": "roryg", | |
"LanguageName": "Caml", | |
"CodeBlock": "module StringMap = Map.Make(String)\n\nlet x =\n StringMap.empty\n |\u003e StringMap.add \"one\" 1\n |\u003e StringMap.add \"two\" 2\n |\u003e StringMap.add \"three\" 3", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:39:15.509783Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3131, | |
"OrigId": 3131, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T22:15:32.320919Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val x = mapOf(\"one\" to 1, \"two\" to 2)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:15:32.320919Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3301, | |
"OrigId": 3301, | |
"Author": "phrank", | |
"CreationDate": "2019-09-27T19:28:17.561009Z", | |
"LastEditor": "phrank", | |
"LanguageName": "C", | |
"CodeBlock": "ENTRY a = {\"foo\", \"twenty\"};\nENTRY b = {\"bar\", \"three\"};\nif (hcreate (23)) {\n hsearch(a, ENTER);\n hsearch(b, ENTER);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/hcreate.html", | |
"AuthorComment": "This POSIX functions maintain a single global hashmap. The GNU C library provides _hcreate_r", | |
"Version": 1, | |
"VersionDate": "2019-09-27T19:28:17.561009Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003csearch.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 29, | |
"Rating": 1, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
13, | |
172 | |
], | |
"RelatedIdiomTitles": [ | |
"Iterate over map keys and values", | |
"Insert entry in map" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 9, | |
"OrigId": 0, | |
"Title": "Create a Binary Tree data structure", | |
"LeadParagraph": "The structure must be recursive because _left child and _right child are binary trees too. A node has access to children nodes, but not to its parent.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [pompito]", | |
"LastEditedImplID": 3408, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 42, | |
"VersionDate": "2019-09-28T06:03:51.737258Z", | |
"Implementations": [ | |
{ | |
"Id": 41, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "class BinTree\u003cT extends Comparable\u003cT\u003e\u003e{\r\n T value;\r\n BinTree\u003cT\u003e left;\r\n BinTree\u003cT\u003e right;\r\n}\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/6J4l4X", | |
"DocumentationURL": "", | |
"AuthorComment": "Note that with this design an empty tree is _null, and thus is not an instance of _BinTree.", | |
"Version": 2, | |
"VersionDate": "2016-12-04T22:16:42.401878Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 42, | |
"OrigId": 42, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "type BinTree struct {\n\tKey keyType\n\tDeco valueType\n\tLeft *BinTree\n\tRight *BinTree\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/MK3qoaVPol", | |
"DocumentationURL": "", | |
"AuthorComment": "_keyType should be easily comparable.\r\n_valueType is a type of value associated with current node, distinct from the key.\r\n\r\nNote that in Go you can call methods of pointer type *BinTree even on a _nil receiver (an empty tree).", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.226523Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 599, | |
"OrigId": 599, | |
"Author": "vbh", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "vbh", | |
"LanguageName": "D", | |
"CodeBlock": "struct BinaryTree(T)\n{\n\tT data;\n\tBinaryTree* left;\n\tBinaryTree* right;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.226523Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 690, | |
"OrigId": 690, | |
"Author": "Therg", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "struct BinTree\u003cT\u003e {\r\n value: T,\r\n left: Option\u003cBox\u003cBinTree\u003cT\u003e\u003e\u003e,\r\n right: Option\u003cBox\u003cBinTree\u003cT\u003e\u003e\u003e,\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-29T09:00:55.065727Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 718, | |
"OrigId": 718, | |
"Author": "lrhn", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "lrhn", | |
"LanguageName": "Dart", | |
"CodeBlock": "class Node\u003cT\u003e {\n final T value;\n Node\u003cT\u003e left, right;\n Node(this.value, {this.left, this.right});\n]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.226523Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 760, | |
"OrigId": 760, | |
"Author": "Geep Jeez", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "Geep Jeez", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type\n generic BinTree\u003cT\u003e = class\n Value: T;\n Left, Right: BinTree;\n end; ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.226523Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 889, | |
"OrigId": 889, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "seigel", | |
"LanguageName": "Ruby", | |
"CodeBlock": "Node = Struct.new(:left, :right, :value)\nparent = Node.new(Node.new, Node.new)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Should also have a place to store the value\r\n", | |
"Version": 2, | |
"VersionDate": "2019-09-26T23:29:47.577024Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 977, | |
"OrigId": 977, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "schuelermine", | |
"LanguageName": "Haskell", | |
"CodeBlock": "data BT x = BEnd | BNode (BT x) x (BT x)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-06-07T10:22:55.446683Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 988, | |
"OrigId": 988, | |
"Author": "hashd", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "defmodule BinaryTree do\r\n\tdefstruct data: nil, left: nil, right: nil\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/bf451110f2", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-02-07T23:33:49.288829Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1342, | |
"OrigId": 1342, | |
"Author": "chai416", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "struct treenode{\r\n int value;\r\n struct treenode* left;\r\n struct treenode* right;\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-23T10:23:01.638105Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1410, | |
"OrigId": 1410, | |
"Author": "TinyFawks", | |
"CreationDate": "2016-02-18T16:57:56.226523Z", | |
"LastEditor": "TinyFawks", | |
"LanguageName": "Python", | |
"CodeBlock": "class Node:\n\tdef __init__(self, data):\n\t\tself.data = data\n\t\tself.left = None\n\t\tself.right = None", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/MXXPa9bQ", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.226523Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1554, | |
"OrigId": 1554, | |
"Author": "Marti_2203", | |
"CreationDate": "2016-02-20T17:34:40.066832Z", | |
"LastEditor": "Marti_2203", | |
"LanguageName": "Csharp", | |
"CodeBlock": "class BinaryTree\u003cT\u003e:IComparable\u003cT\u003e\r\n{\r\n T value;\r\n BinaryTree\u003cT\u003e leftChild;\r\n BinaryTree\u003cT\u003e rightChild;\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-20T17:34:40.066832Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1619, | |
"OrigId": 1619, | |
"Author": "agilla1", | |
"CreationDate": "2016-03-28T12:33:53.173236Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "class BNode\n{\n public $data;\n public $lNode;\n public $rNode;\n\n public function __construct($item)\n {\n $this-\u003edata = $item;\n $this-\u003elNode = null;\n $this-\u003erNode = null;\n }\n}", | |
"OriginalAttributionURL": "http://www.sitepoint.com/data-structures-2/", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T10:16:29.933603Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1753, | |
"OrigId": 1753, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-07-12T21:07:45.572634Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-type binary_tree(T) ::\r\n\t#{ data := T\r\n\t , left := binary_tree(T)\r\n\t , right := binary_tree(T)\r\n\t }.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "We just define the type here. Next step would be to implement a module with the required functions to access it and even make it opaque.", | |
"Version": 1, | |
"VersionDate": "2016-07-12T21:07:45.572634Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2025, | |
"OrigId": 2025, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-12T15:33:41.518254Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (make-btree value left right)\n (cons value (cons left right)))\n\n(define (btree-value bt) (car bt))\n(define (btree-left bt) (cadr bt))\n(define (btree-right bt) (cddr bt))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-12T15:33:41.518254Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2262, | |
"OrigId": 2262, | |
"Author": "Kng", | |
"CreationDate": "2018-04-03T08:21:39.18348Z", | |
"LastEditor": "Kng", | |
"LanguageName": "Lua", | |
"CodeBlock": "local function BinTree(v, l, r)\n\treturn {\n\t\tval = v,\n\t\tleft = l,\n\t\tright = r\n\t}\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-04-03T08:21:39.18348Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2520, | |
"OrigId": 2520, | |
"Author": "1.7.4", | |
"CreationDate": "2019-01-23T17:28:24.203105Z", | |
"LastEditor": "1.7.4", | |
"LanguageName": "JS", | |
"CodeBlock": "class Node {\n constructor (data) {\n this.data = data\n this.left = null\n this.right = null\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-01-23T17:30:24.227621Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2521, | |
"OrigId": 2521, | |
"Author": "1.7.4", | |
"CreationDate": "2019-01-23T17:29:59.037001Z", | |
"LastEditor": "1.7.4", | |
"LanguageName": "JS", | |
"CodeBlock": "class Node {\n constructor (data) {\n this.data = data\n this.left = null\n this.right = null\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-01-23T17:29:59.037001Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2879, | |
"OrigId": 2879, | |
"Author": "Dirk", | |
"CreationDate": "2019-09-26T16:39:19.434995Z", | |
"LastEditor": "Dirk", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defclass node ()\n ((value \n :initarg :value :initform nil \n :accessor node-value)\n (left-child \n :initarg :left-child :initform nil \n :accessor node-left-child)\n (right-child \n :initarg :right-child :initform nil \n :accessor node-right-child)))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.lispworks.com/documentation/lw70/CLHS/Body/m_defcla.htm#defclass", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:42:33.686753Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3080, | |
"OrigId": 3080, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:28:07.903544Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Clojure", | |
"CodeBlock": "type treenode\n integer :: value\n type (treenode), pointer :: left\n type (treenode), pointer :: right\nend type treenode", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:28:07.903544Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3145, | |
"OrigId": 3145, | |
"Author": "roryg", | |
"CreationDate": "2019-09-26T23:15:58.123078Z", | |
"LastEditor": "roryg", | |
"LanguageName": "Caml", | |
"CodeBlock": "type treenode =\n Node of {\n value: int;\n left: treenode;\n right: treenode\n }\n | Leaf", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T23:15:58.123078Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3176, | |
"OrigId": 3176, | |
"Author": "atdt", | |
"CreationDate": "2019-09-27T03:58:30.712754Z", | |
"LastEditor": "atdt", | |
"LanguageName": "Python", | |
"CodeBlock": "class Node:\n def __init__(self, data, left_child, right_child):\n self.data = data\n self._left_child = left_child\n self._right_child = right_child", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T03:58:30.712754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3188, | |
"OrigId": 3188, | |
"Author": "daxim", | |
"CreationDate": "2019-09-27T07:45:57.792625Z", | |
"LastEditor": "daxim", | |
"LanguageName": "Perl", | |
"CodeBlock": "class Tree::Binary {\n has 'left', is =\u003e 'ro', isa =\u003e Maybe[InstanceOf['Tree::Binary']];\n has 'right', is =\u003e 'ro', isa =\u003e Maybe[InstanceOf['Tree::Binary']];\n has 'val', is =\u003e 'ro', isa =\u003e Int;\n}\nmy $t = Tree::Binary-\u003enew(\n val =\u003e 42,\n left =\u003e Tree::Binary-\u003enew(val =\u003e 23),\n right =\u003e Tree::Binary-\u003enew(\n val =\u003e 1729,\n right =\u003e Tree::Binary-\u003enew(val =\u003e -1)\n )\n);\n__END__\n 42\n ↙ ↘\n 23 1729\n ↙ ↘ ↙ ↘\n∅ ∅ ∅ -1\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://p3rl.org/Moops", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T07:45:57.792625Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use Moops;\r\n", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3398, | |
"OrigId": 3398, | |
"Author": "chardan", | |
"CreationDate": "2019-09-28T00:30:42.347843Z", | |
"LastEditor": "chardan", | |
"LanguageName": "Cpp", | |
"CodeBlock": "struct binary_tree\n{\n binary_tree *left = nullptr, *right = nullptr;\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-28T00:30:42.347843Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3408, | |
"OrigId": 3408, | |
"Author": "pompito", | |
"CreationDate": "2019-09-28T06:03:51.73381Z", | |
"LastEditor": "pompito", | |
"LanguageName": "Fortran", | |
"CodeBlock": "type binary_tree\n integer :: value\n type(binary_tree), allocatable :: left\n type(binary_tree), allocatable :: right\nend type binary_tree", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-28T06:03:51.73381Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 25, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
16, | |
17 | |
], | |
"RelatedIdiomTitles": [ | |
"Depth-first traversing of a binary tree", | |
"Create a Tree data structure" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 10, | |
"OrigId": 0, | |
"Title": "Shuffle a list", | |
"LeadParagraph": "Generate a random permutation of the elements of list _x", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New VB implementation by user [EvilGenius]", | |
"LastEditedImplID": 3370, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 77, | |
"VersionDate": "2019-09-27T23:26:30.751061Z", | |
"Implementations": [ | |
{ | |
"Id": 43, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "Collections.shuffle(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#shuffle%28java.util.List%29", | |
"AuthorComment": "Already implemented in standard library.\r\nThis method alters the list.\r\nIf you need predictable results, see shuffle(List\u003c?\u003e, Random).", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Collections;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 44, | |
"OrigId": 44, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "for i := range x {\r\n\tj := rand.Intn(i + 1)\r\n\tx[i], x[j] = x[j], x[i]\r\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/12264789/shuffle-array-in-go#answer-12267471", | |
"DemoURL": "http://play.golang.org/p/pQzPCChqI1", | |
"DocumentationURL": "", | |
"AuthorComment": "This alters the slice content.\r\nThis requires no extra allocation.", | |
"Version": 2, | |
"VersionDate": "2016-02-22T10:30:55.067922Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 66, | |
"OrigId": 66, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x.shuffle", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-04-13T22:11:52.102943Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 182, | |
"OrigId": 182, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "shuffle(x)", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/976882/shuffling-a-list-of-objects-in-python/976918#976918", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This alters the list", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "from random import shuffle", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 204, | |
"OrigId": 204, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "x.shuffle();", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/23905948/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This alters the content of _x.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 301, | |
"OrigId": 301, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "@shuffled = shuffle('a', 'b', 'c', 'd', 'e', 'f');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "List::Util -- one of the many useful perl modules found on CPAN.org", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use List::Util 'shuffle';", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 359, | |
"OrigId": 359, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "for (var i in items) {\n var j = Math.floor(items.length * Math.random()),\n tmp = items[i]; items[i]=items[j]; items[j]=tmp;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Not the best version, just the best that I know (so far!)", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 410, | |
"OrigId": 410, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "let mut rng = StdRng::new().unwrap();\nrng.shuffle(\u0026mut x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Requires the rand crate (https://crates.io/crates/rand)", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extern crate rand;\r\nuse rand::{Rng, StdRng};", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 459, | |
"OrigId": 459, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "shuffle($x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_shuffle() is PHP built-in function. It shuffles array in place and returns true on success.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 516, | |
"OrigId": 516, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "schveiguy", | |
"LanguageName": "D", | |
"CodeBlock": "randomShuffle(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Use optional second parameter to specify random number generator to use.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.random;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 617, | |
"OrigId": 617, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var shuffled = x.toList()..shuffle();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/ac99cb5c41ee4322c5e7", | |
"DocumentationURL": "", | |
"AuthorComment": "This keeps _x unchanged.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 720, | |
"OrigId": 720, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "xd", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var Iter,rr: integer; \n[...]\n for Iter := 0 to high(List) do\n begin\n rr := random(high(List))+1;\n tmp := List[Iter];\n List[Iter] := List[rr];\n List[rr] := tmp;\n end;\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Go through each element of the list and swap it with a random element.", | |
"Version": 2, | |
"VersionDate": "2018-07-01T14:55:25.013905Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 826, | |
"OrigId": 826, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "shuffle x = if length x \u003c 2 then return x else do\n\ti \u003c- System.Random.randomRIO (0, length(x)-1)\n\tr \u003c- shuffle (take i x ++ drop (i+1) x)\n\treturn (x!!i : r)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 837, | |
"OrigId": 837, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "shuffled_list = x.shuffle", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/Array.html#method-i-shuffle", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-07-01T19:56:22.478842Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 909, | |
"OrigId": 909, | |
"Author": "anonyfox", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "y = Enum.shuffle x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://elixirplayground.com?gist=1ab3cd1688074559fa25ebed90d19489", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/Enum.html#shuffle/1", | |
"AuthorComment": "_x is left unchanged.", | |
"Version": 2, | |
"VersionDate": "2016-05-28T22:59:50.972405Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1005, | |
"OrigId": 1005, | |
"Author": "daleardi", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Erlang", | |
"CodeBlock": "[Y||{_,Y} \u003c- lists:sort([ {rand:uniform(), N} || N \u003c- X])].", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/8817171/shuffling-elements-in-a-list-randomly-re-arrange-list-elements", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Variables are capitalized.", | |
"Version": 4, | |
"VersionDate": "2018-07-08T09:54:33.021165Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1249, | |
"OrigId": 1249, | |
"Author": "mikee", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "mikee", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::random_shuffle(my_collection.begin(), my_collection.end());", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/algorithm/random_shuffle", | |
"AuthorComment": "Already implemented in the standard library (algorithm)\r\nThis version uses the built-in random generator", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "#include \u003calgorithm\u003e\r\n#include \u003cvector\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1313, | |
"OrigId": 1313, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "shuffled = {}\nfor i, v in ipairs(x) do\n\tlocal pos = math.random(1, #shuffled+1)\n\ttable.insert(shuffled, pos, v)\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "While not technically necessary, we really ought to have math.randomseed(os.time()) or something similar above, or we'll get the same \"random\" sequence every time.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1351, | |
"OrigId": 1351, | |
"Author": "Mihir", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "Mihir", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(shuffle collection)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojuredocs.org/clojure.core/shuffle", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1352, | |
"OrigId": 1352, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "private static Random rng = new Random(); \n\npublic static void Shuffle\u003cT\u003e(this IList\u003cT\u003e list) \n{ \n int n = list.Count; \n while (n \u003e 1) { \n n--; \n int k = rng.Next(n + 1); \n T value = list[k]; \n list[k] = list[n]; \n list[n] = value; \n } \n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/1262619", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "There is no built-in method to support the randomization of a _List. This creates an extension method that adds this functionality to any provided _List. _rng should be declared as a global variable so that only one Random object is created.\r\n\r\nSee the original attribution URL for better explanation.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "System;\r\nSystem.Collections.Generic;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1438, | |
"OrigId": 1438, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val items = List(1, 2, 3, 4, 5)\nval shuffledItems = Random.shuffle(items)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "import scala.util.Random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1475, | |
"OrigId": 1475, | |
"Author": "mdciotti", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "mdciotti", | |
"LanguageName": "JS", | |
"CodeBlock": "for (var i = x.length - 1; i \u003e 0; i--) {\n var j = Math.floor(Math.random() * (i + 1));\n var temp = x[j];\n x[j] = x[i];\n x[i] = temp;\n}", | |
"OriginalAttributionURL": "https://en.wikipedia.org/wiki/Fisher–Yates_shuffle", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Shuffle a list in-place using the Fisher-Yates algorithm.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1478, | |
"OrigId": 1478, | |
"Author": "Trshant", | |
"CreationDate": "2016-02-18T16:57:56.460583Z", | |
"LastEditor": "Trshant", | |
"LanguageName": "Python", | |
"CodeBlock": "random.shuffle(list)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://pythonfiddle.com/shuffle-the-data/", | |
"DocumentationURL": "https://docs.python.org/2/library/random.html#random.shuffle", | |
"AuthorComment": "_random._shuffle is a inbuilt function that will shuffle the data.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.460583Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1564, | |
"OrigId": 1564, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-22T10:36:01.129689Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "y := make([]T, len(x))\r\nperm := rand.Perm(len(x))\r\nfor i, v := range perm {\r\n\ty[v] = x[i]\r\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/12264918/871134", | |
"DemoURL": "http://play.golang.org/p/ZAxr7WIeE1", | |
"DocumentationURL": "https://golang.org/pkg/math/rand/#Perm", | |
"AuthorComment": "This allocates a temporary slice of _int, and a new destination slice _y of type _T.\r\n_x is left unchanged.", | |
"Version": 1, | |
"VersionDate": "2016-02-22T10:36:01.129689Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1995, | |
"OrigId": 1995, | |
"Author": "Dodopod", | |
"CreationDate": "2017-05-27T19:23:50.183586Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "C", | |
"CodeBlock": "srand(time(NULL));\nfor (int i = 0; i \u003c N-1; ++i)\n{\n int j = rand() % (N-i) + i;\n int temp = x[i];\n x[i] = x[j];\n x[j] = temp;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Shuffles an array of _n _ints in-place using Fisher-Yates algorithm.", | |
"Version": 1, | |
"VersionDate": "2017-05-27T19:23:50.183586Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e\r\n#include \u003ctime.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2019, | |
"OrigId": 2019, | |
"Author": "nobody", | |
"CreationDate": "2017-06-08T01:14:50.101202Z", | |
"LastEditor": "Scroncho", | |
"LanguageName": "Lua", | |
"CodeBlock": "function(list)\n\tfor i = #list, 2, -1 do\n\t\tlocal j = math.random(i)\n\t\tlist[i], list[j] = list[j], list[i]\n\tend\nend\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Fisher-Yates shuffle, in-place – for each position, pick an element from those not yet picked", | |
"Version": 5, | |
"VersionDate": "2018-04-22T15:13:06.61332Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2021, | |
"OrigId": 2021, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-09T15:29:15.10688Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(shuffle x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-09T15:29:15.10688Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2230, | |
"OrigId": 2230, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2018-02-13T09:19:14.472285Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "rand.Shuffle(len(x), func(i, j int) {\n\tx[i], x[j] = x[j], x[i]\n})", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/-2QPB-IcbXG", | |
"DocumentationURL": "https://golang.org/pkg/math/rand/#Shuffle", | |
"AuthorComment": "Last argument is a _swap func.\r\n\r\nThis works in Go ≥ 1.10", | |
"Version": 1, | |
"VersionDate": "2018-02-13T09:19:14.472285Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2329, | |
"OrigId": 2329, | |
"Author": "GobbleCock", | |
"CreationDate": "2018-06-11T19:14:59.370158Z", | |
"LastEditor": "wsll5460", | |
"LanguageName": "Rust", | |
"CodeBlock": "let mut rng = thread_rng();\nlet mut y = [1, 2, 3, 4, 5];\nprintln!(\"Unshuffled: {:?}\", y);\ny.shuffle(\u0026mut rng);\nprintln!(\"Shuffled: {:?}\", y);", | |
"OriginalAttributionURL": "https://rust-random.github.io/rand/rand/seq/trait.SliceRandom.html#example-3", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2018\u0026gist=e343fd6c1ec3ec41a03dc18997a12282", | |
"DocumentationURL": "https://rust-random.github.io/rand/rand/seq/trait.SliceRandom.html#tymethod.shuffle", | |
"AuthorComment": "Requires the rand crate.\r\n(https://crates.io/crates/rand)", | |
"Version": 6, | |
"VersionDate": "2019-05-29T02:09:06.487907Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use rand::seq::SliceRandom;\r\nuse rand::thread_rng;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2991, | |
"OrigId": 2991, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:58:40.834697Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "mutableList.shuffle()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Only mutable lists can be shuffled in-place.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:58:40.834697Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2992, | |
"OrigId": 2992, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:59:42.090843Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val newList = list.shuffled()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Immutable lists cannot be shuffled in-place.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:59:42.090843Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3146, | |
"OrigId": 3146, | |
"Author": "jupiter", | |
"CreationDate": "2019-09-26T23:26:01.76236Z", | |
"LastEditor": "jupiter", | |
"LanguageName": "Fortran", | |
"CodeBlock": "\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T23:43:33.919385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3147, | |
"OrigId": 3147, | |
"Author": "jupiter", | |
"CreationDate": "2019-09-26T23:40:46.686842Z", | |
"LastEditor": "jupiter", | |
"LanguageName": "Fortran", | |
"CodeBlock": "module M_shuffle\ncontains\nfunction scramble( number_of_values ) result(array)\n integer,intent(in) :: number_of_values\n integer,allocatable :: array(:)\n array=[(i,i=1,number_of_values)]\n n=1; m=number_of_values\n do k=1,2\n do i=1,m\n call random_number(u)\n j = n + FLOOR((m+1-n)*u)\n itemp=array(j); array(j)=array(i); array(i)=itemp\n enddo\n enddo\nend function scramble\nend module M_shuffle\n :\nuse M_shuffle, only : scramble\nnewlist=list(scramble(size(list))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The SCRAMBLE function returns an integer array of the size specified\r\npopulated with the numbers 1 to \"number_of_values\" in random order.\r\n\r\nA simple way to randomly scramble a list of any type is to create a\r\nrandom permutation of all the index values of the array and then access\r\nthe original list elements using that list of indices. The list itself\r\ncan be re-ordered very succintly using array syntax.\r\n", | |
"Version": 1, | |
"VersionDate": "2019-09-26T23:40:46.686842Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3370, | |
"OrigId": 3370, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:26:30.74682Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Function Shuffle(Of T)(collection As IEnumerable(Of T)) As List(Of T)\n Dim r As Random = New Random()\n Shuffle = collection.OrderBy(Function(a) r.Next()).ToList()\nEnd Function", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:26:30.74682Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 34, | |
"Rating": 3, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
21, | |
158, | |
11 | |
], | |
"RelatedIdiomTitles": [ | |
"Swap values of variables a and b", | |
"Random sublist", | |
"Pick a random element from a list" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 11, | |
"OrigId": 0, | |
"Title": "Pick a random element from a list", | |
"LeadParagraph": "List _x must be non-empty.", | |
"ExtraKeywords": "choose", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [tkoenig]", | |
"LastEditedImplID": 3064, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/11/random-hat-t.png", | |
"Version": 80, | |
"VersionDate": "2019-09-26T20:01:38.522833Z", | |
"Implementations": [ | |
{ | |
"Id": 45, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "yusufaytas", | |
"LanguageName": "Java", | |
"CodeBlock": "x.get((int)(Math.random()*x.size()))", | |
"OriginalAttributionURL": "http://rosettacode.org/wiki/Pick_random_element#Java", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Consider reusing the _Random object, don't create it each time you pick an element.", | |
"Version": 4, | |
"VersionDate": "2019-09-26T19:05:40.496794Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 46, | |
"OrigId": 46, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "x[Math.floor(Math.random() * x.length)]", | |
"OriginalAttributionURL": "http://rosettacode.org/wiki/Pick_random_element#JavaScript", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:25.813051Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 47, | |
"OrigId": 47, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "random.choice(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:25.813051Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 48, | |
"OrigId": 48, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "x[rand.Intn(len(x))]", | |
"OriginalAttributionURL": "http://rosettacode.org/wiki/Pick_random_element#Go", | |
"DemoURL": "http://play.golang.org/p/q2lh3ma3fa", | |
"DocumentationURL": "https://golang.org/pkg/math/rand/#Intn", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-04-20T20:26:13.217655Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 52, | |
"OrigId": 52, | |
"Author": "Otakode", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "x[rand() % x_length];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_rand needs to be initialized by calling void _srand(unsigned int);", | |
"Version": 2, | |
"VersionDate": "2016-11-25T09:36:34.198096Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 236, | |
"OrigId": 236, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "$x[ array_rand($x) ]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/array_rand", | |
"AuthorComment": "_array_rand returns the key, and we want the value.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:25.813051Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 297, | |
"OrigId": 297, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my @x = ('a', 'list', 'of', 'random', 'items');\r\n\r\nprint $list[ rand(@x) ], \"\\n\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "In scalar context (such as the call to _rand), an array evaluates to the _length.", | |
"Version": 2, | |
"VersionDate": "2016-04-21T10:20:55.102519Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 553, | |
"OrigId": 553, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "x.randomSample(1);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:25.813051Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.random;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 613, | |
"OrigId": 613, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "x[new Random().nextInt(x.length)];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/2c6b2c5ea918c995aa09", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:25.813051Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 657, | |
"OrigId": 657, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "element := x[random(length(x))];\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "if _x is an Array", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:25.813051Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 658, | |
"OrigId": 658, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "element := x.Items[random(x.count)];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "If _x is a _TList or _TStrings -descendent", | |
"Version": 2, | |
"VersionDate": "2016-02-07T20:42:47.235298Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses classes;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 828, | |
"OrigId": 828, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "hrschueler", | |
"LanguageName": "Haskell", | |
"CodeBlock": "(\\l g -\u003e l !! (randomR (0, length l) g))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2018-04-17T16:49:18.203232Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import System.Random (randomR)", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 906, | |
"OrigId": 906, | |
"Author": "rrrene", | |
"CreationDate": "2015-11-30T12:37:25.813051Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Enum.random(x)\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/f9f0161650", | |
"DocumentationURL": "http://elixir-lang.org/docs/stable/elixir/Enum.html#random/1", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2016-11-30T21:35:05.300553Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1122, | |
"OrigId": 1122, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T02:41:24.441052Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "ktn_random:pick(X)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://github.com/inaka/erlang-katana/blob/master/src/ktn_random.erl#L49", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-12-18T02:41:24.441052Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "https://github.com/inaka/erlang-katana", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1123, | |
"OrigId": 1123, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T02:47:12.360349Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "lists:nth(rand:uniform(length(X)), X).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=1ef3", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/rand.html?i=1\u0026search=rand:un#uniform/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-12-18T02:47:12.360349Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1326, | |
"OrigId": 1326, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T16:19:01.022495Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "x[math.random(#x)]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:19:01.022495Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1328, | |
"OrigId": 1328, | |
"Author": "akavi", | |
"CreationDate": "2016-02-16T16:29:25.641075Z", | |
"LastEditor": "programming-idioms", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x.sample", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.ruby-lang.org/en/2.5.0/Array.html#method-i-sample", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-11-21T12:56:45.475291Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1445, | |
"OrigId": 1445, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:50:22.18749Z", | |
"LastEditor": "hrschueler", | |
"LanguageName": "Scala", | |
"CodeBlock": "val x = List(1, 2, 3, 4)\nx.apply(Random.nextInt(x.size))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_apply can be called without the name or dot\r\nx(Random.nextInt(x.size))", | |
"Version": 3, | |
"VersionDate": "2018-04-17T16:50:12.15577Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import scala.util.Random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1491, | |
"OrigId": 1491, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T10:54:04.8346Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "x[new Random().Next(x.Count)];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-02-17T13:08:42.470691Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System;\r\nusing System.Collections.Generic;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1699, | |
"OrigId": 1699, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-04-20T20:23:02.241955Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func pickT(x []T) T {\r\n\treturn x[rand.Intn(len(x))]\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/u6Db7wb7v_", | |
"DocumentationURL": "https://golang.org/pkg/math/rand/#Intn", | |
"AuthorComment": "If you decide to implement _pickT, you will have to write it separately for each desired type _T.", | |
"Version": 2, | |
"VersionDate": "2016-04-20T20:24:53.896012Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1960, | |
"OrigId": 1960, | |
"Author": "Tim", | |
"CreationDate": "2017-04-07T18:30:59.107194Z", | |
"LastEditor": "Tim", | |
"LanguageName": "Rust", | |
"CodeBlock": "x[rand::thread_rng().gen_range(0, x.len())]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://doc.rust-lang.org/rand/rand/trait.Rng.html", | |
"AuthorComment": "gen_range returns a number between 0 (inclusive) and x.len() (exclusive)", | |
"Version": 1, | |
"VersionDate": "2017-04-07T18:30:59.107194Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use rand::{self, Rng};", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2102, | |
"OrigId": 2102, | |
"Author": "Jerry", | |
"CreationDate": "2017-09-01T15:50:56.186264Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(rand-nth x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-09-01T18:31:55.93282Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2212, | |
"OrigId": 2212, | |
"Author": "benbika", | |
"CreationDate": "2018-01-14T17:27:28.253851Z", | |
"LastEditor": "benbika", | |
"LanguageName": "Haskell", | |
"CodeBlock": "(l !!) \u003c$\u003e randomRIO (0, length l - 1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-01-14T17:27:28.253851Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "import System.Random (randomRIO)", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2309, | |
"OrigId": 2309, | |
"Author": "fantasy", | |
"CreationDate": "2018-05-08T01:23:30.902505Z", | |
"LastEditor": "fantasy", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::mt19937 gen;\nstd::uniform_int_distribution\u003csize_t\u003e uid (0, x.size () - 1);\nx[uid (gen)];\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Assuming that _x.size () \u003e 0", | |
"Version": 1, | |
"VersionDate": "2018-05-08T01:23:30.902505Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003crandom\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2330, | |
"OrigId": 2330, | |
"Author": "GobbleCock", | |
"CreationDate": "2018-06-11T19:30:25.910129Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let choice = thread_rng().choose(\u0026x).unwrap();\n", | |
"OriginalAttributionURL": "https://docs.rs/rand/0.5.1/rand/trait.Rng.html#example-7", | |
"DemoURL": "https://play.rust-lang.org/?gist=b84ee25d8824dd5e6de907337afce901\u0026version=stable\u0026mode=debug", | |
"DocumentationURL": "https://docs.rs/rand/0.5.1/rand/trait.Rng.html#method.choose", | |
"AuthorComment": "Requires the rand crate.\r\n(https://crates.io/crates/rand)\r\n\r\nThe _choose method returns an _Option which is _None if _x is empty.", | |
"Version": 3, | |
"VersionDate": "2018-08-03T20:33:59.760741Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extern crate rand;\r\nuse rand::{thread_rng, Rng};", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2637, | |
"OrigId": 2637, | |
"Author": "Yorizzz", | |
"CreationDate": "2019-05-02T09:08:31.786456Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "x.get(ThreadLocalRandom.current().nextInt(0, x.size()))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Using _ThreadLocalRandom prevents unnecessary allocation of a new Random, and is more efficient in a multi-threaded application", | |
"Version": 2, | |
"VersionDate": "2019-05-05T16:11:15.641808Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.concurrent.ThreadLocalRandom;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2852, | |
"OrigId": 2852, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:06:40.776324Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(nth (random (length x)) x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:06:40.776324Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2853, | |
"OrigId": 2853, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:06:41.100233Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(nth (random (length x)) x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:06:41.100233Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3016, | |
"OrigId": 3016, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T18:47:48.312627Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "list.random()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T18:47:48.312627Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3064, | |
"OrigId": 3064, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:01:38.518834Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "\ncall random_number (a)\nx(lbound(x) + int(a*ubound(x))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:01:38.518834Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 30, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
10 | |
], | |
"RelatedIdiomTitles": [ | |
"Shuffle a list" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 12, | |
"OrigId": 0, | |
"Title": "Check if list contains a value", | |
"LeadParagraph": "Check if _list contains a value _x.\r\n_list is an iterable finite container.", | |
"ExtraKeywords": "array vector", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [spectrum]", | |
"LastEditedImplID": 3435, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/12/list_contains.png", | |
"Version": 88, | |
"VersionDate": "2019-09-28T13:38:23.983617Z", | |
"Implementations": [ | |
{ | |
"Id": 49, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func Contains(list []T, x T) bool {\r\n\tfor _, item := range list {\r\n\t\tif item == x {\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\treturn false\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/T8EFp_407q", | |
"DocumentationURL": "https://golang.org/ref/spec#Comparison_operators", | |
"AuthorComment": "This func must be written for each type _T of your needs (with a different name each).\r\n\r\nYou may use any type _T compatible with operator ==", | |
"Version": 2, | |
"VersionDate": "2016-05-04T11:38:02.03804Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 50, | |
"OrigId": 50, | |
"Author": "Otakode", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "Stanley", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::find_if(list.begin(),list.end(),x) != list.end();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2019-09-27T07:32:32.578288Z", | |
"Rating": -2, | |
"Checked": false, | |
"ImportsBlock": "#include \u003calgorithm\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 51, | |
"OrigId": 51, | |
"Author": "Otakode", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "g", | |
"LanguageName": "Cpp", | |
"CodeBlock": "bool Contains(const std::vector\u003cint\u003e \u0026list, int x)\n{\n\treturn std::find(list.begin(), list.end(), x) != list.end();\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.cplusplus.com/reference/algorithm/find/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 2, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cvector\u003e\r\n#include \u003calgorithm\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 59, | |
"OrigId": 59, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "nv", | |
"LanguageName": "Ruby", | |
"CodeBlock": "list.include?( x )", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 154, | |
"OrigId": 154, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (contains list x)\n (cond \n ((null? list) #f)\n ((eq? (car list) x) #t)\n (else (contains (cdr list) x))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://repl.it/SIT", | |
"DocumentationURL": "", | |
"AuthorComment": "This is a custom implementation, use it if no built-in predicate is available in your Scheme environment.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 181, | |
"OrigId": 181, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "schuelermine", | |
"LanguageName": "Python", | |
"CodeBlock": "x in list", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This indirectly calls list.__contains__() and returns True or False", | |
"Version": 2, | |
"VersionDate": "2019-06-07T10:27:12.157819Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 219, | |
"OrigId": 219, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "boolean contains(int[] list, int x){\n for(int y:list)\n if( y==x )\n return true;\n return false;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This applies to an array of primitive values, e.g. _int", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 220, | |
"OrigId": 220, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "boolean \u003cT\u003e contains(T[] list, T x){\n if( x==null){\n for(T y:list)\n if( y==null )\n return true;\n }else{\n for(T y:list)\n if( x.equals(y) )\n return true;\n }\n return false;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This applies to an array of any non-primitive type _T", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": -2, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 221, | |
"OrigId": 221, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "list.contains(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This applies to any _List\u003c_T\u003e", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "import java.util.List;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 293, | |
"OrigId": 293, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "# To check an array for a value:\nprint \"Found 'foo'\\n\" if grep { $_ eq 'foo' } @a_list;\n\n# To check a map for a value:\nprint \"Found 'bar'\\n\" if exists $map{bar};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The inside of the curly braces for a hash(map) reference is automatically stringified.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 355, | |
"OrigId": 355, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "fibre", | |
"LanguageName": "JS", | |
"CodeBlock": "return list.includes(x) // newer\nreturn list.indexOf(x) !== -1 // older", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf", | |
"AuthorComment": "Array.prototype.includes() is preferred but if you are supporting browsers that are 5+ years old, for example IE 11 , and you are not using a transpiler, then the old syntax is generally well-understood. ", | |
"Version": 4, | |
"VersionDate": "2019-09-26T15:50:43.082197Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 414, | |
"OrigId": 414, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "list.contains(\u0026x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://is.gd/iugb8l", | |
"DocumentationURL": "https://doc.rust-lang.org/std/primitive.slice.html#method.contains", | |
"AuthorComment": "See also more general alternative implementations.", | |
"Version": 3, | |
"VersionDate": "2017-05-21T22:07:17.976551Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 465, | |
"OrigId": 465, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "in_array($x, $list, true);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_in_array returns _true if value exists in array _$list\r\n\r\nLast argument should be set to _true. Otherwise unexpected behavior is very likely to happen, for details see php manual.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:06:40.633107Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 512, | |
"OrigId": 512, | |
"Author": "bbtemp", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "bbtemp", | |
"LanguageName": "D", | |
"CodeBlock": "bool here = canFind(items, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "canFind(_haystack, _needle)", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm.searching;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 603, | |
"OrigId": 603, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "list.contains(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/a9da4925cd06bfabcba1", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 654, | |
"OrigId": 654, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "result := false;\nfor e in list do \n\tif e=x then\n\t\tbegin\n\t\t\tresult := true;\n\t\t\tbreak;\n\t\tend\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 655, | |
"OrigId": 655, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "result := list.IndexOf(x) \u003c\u003e -1;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "If list is a _TStrings-descendant ", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses classes;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 800, | |
"OrigId": 800, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "ac", | |
"LanguageName": "Haskell", | |
"CodeBlock": "x `elem` list", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Foldable.html#v:elem", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2019-09-26T15:00:44.459983Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 807, | |
"OrigId": 807, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(some (partial = x) list)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/some", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 898, | |
"OrigId": 898, | |
"Author": "rrrene", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Enum.member?(list, x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/f74e5775f8", | |
"DocumentationURL": "http://elixir-lang.org/docs/stable/elixir/Enum.html#member?/2", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T21:11:42.749615Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1064, | |
"OrigId": 1064, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "lists:member(X, List).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=0\u0026search=lists:memb#member/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1217, | |
"OrigId": 1217, | |
"Author": "piou", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "bool contains(int x, int* list, size_t list_len) {\n for (int i=0 ; i\u003clist_len ; i++)\n if (list[i] == x)\n return true;\n return false;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdbool.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1300, | |
"OrigId": 1300, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "function contains(list, x)\n\tfor _, v in pairs(list) do\n\t\tif v == x then return true end\n\tend\n\treturn false\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1308, | |
"OrigId": 1308, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "Result := Items.Contains (X);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Containers.Vectors;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1344, | |
"OrigId": 1344, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "list.Contains(item);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This applies to any _List\u003c_T\u003e", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "System.Collections.Generic", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1431, | |
"OrigId": 1431, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:56.731679Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val items: Seq[String] = List(\"a\", \"b\", \"c\")\nitems.contains(\"a\")\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:56.731679Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1966, | |
"OrigId": 1966, | |
"Author": "mmx", | |
"CreationDate": "2017-04-19T04:57:30.47366Z", | |
"LastEditor": "fibre", | |
"LanguageName": "JS", | |
"CodeBlock": "return list.includes(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes", | |
"AuthorComment": "ES7 (Works on strings from ES6)", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:51:26.758391Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1984, | |
"OrigId": 1984, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-05-21T22:03:54.261554Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "list.iter().any(|v| v == \u0026x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://is.gd/VlI045", | |
"DocumentationURL": "", | |
"AuthorComment": "This works for most iterable types.", | |
"Version": 1, | |
"VersionDate": "2017-05-21T22:03:54.261554Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1985, | |
"OrigId": 1985, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-05-21T22:05:41.800561Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "(\u0026list).into_iter().any(|v| v == \u0026x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://is.gd/hZWiKW", | |
"DocumentationURL": "https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#tymethod.into_iter", | |
"AuthorComment": "This is the the truly general version, but it isn't the most idiomatic.", | |
"Version": 2, | |
"VersionDate": "2017-05-21T22:11:30.38315Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2479, | |
"OrigId": 2479, | |
"Author": "Shoo", | |
"CreationDate": "2018-12-27T12:15:22.251937Z", | |
"LastEditor": "Shoo", | |
"LanguageName": "Erlang", | |
"CodeBlock": "member(_, []) -\u003e false;\nmember(Value, [H|T]) -\u003e \n case H of\n Value -\u003e true;\n _ -\u003e member(T)\n end.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-12-27T12:17:11.234486Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2480, | |
"OrigId": 2480, | |
"Author": "Foxy", | |
"CreationDate": "2018-12-27T12:22:51.323818Z", | |
"LastEditor": "Foxy", | |
"LanguageName": "Erlang", | |
"CodeBlock": "member(_, []) -\u003e false;\nmember(Value, [H|_]) where Value =:= H -\u003e true;\nmember(Value, [_|T]) -\u003e member(Value, T).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-12-27T12:22:51.323818Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2747, | |
"OrigId": 2747, | |
"Author": "raphaelschaad", | |
"CreationDate": "2019-09-26T14:33:23.003698Z", | |
"LastEditor": "raphaelschaad", | |
"LanguageName": "Obj-C", | |
"CodeBlock": "[list containsObject:x];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Objects are considered equal if `isEqual:` returns YES.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:33:23.003698Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2767, | |
"OrigId": 2767, | |
"Author": "n0nick", | |
"CreationDate": "2019-09-26T14:49:32.121977Z", | |
"LastEditor": "n0nick", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.include? x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://ruby-doc.org/core-1.9.3/Array.html#method-i-include-3F", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:49:32.121977Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2768, | |
"OrigId": 2768, | |
"Author": "n0nick", | |
"CreationDate": "2019-09-26T14:50:05.835246Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "items.includes(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:37:28.765213Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2771, | |
"OrigId": 2771, | |
"Author": "dland", | |
"CreationDate": "2019-09-26T14:54:15.831573Z", | |
"LastEditor": "dland", | |
"LanguageName": "Perl", | |
"CodeBlock": "print \"ok\\n\" if first {$_ eq 'needle'} @haystack;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://perldoc.perl.org/List/Util.html", | |
"AuthorComment": "_grep() will find _all the elements that match... in a large list this may waste time. _first() will return true as soon as the element is found.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:54:15.831573Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "List::Util 'first'", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2786, | |
"OrigId": 2786, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:08:05.665221Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(member x list)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:08:05.665221Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2823, | |
"OrigId": 2823, | |
"Author": "frekw", | |
"CreationDate": "2019-09-26T15:39:05.339563Z", | |
"LastEditor": "frekw", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(some #{x} list)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:39:05.339563Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2881, | |
"OrigId": 2881, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:42:02.207194Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "List.mem value list", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:42:02.207194Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2960, | |
"OrigId": 2960, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:32:28.653341Z", | |
"LastEditor": "jtang", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "x in list", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "list.contains(x) also works", | |
"Version": 3, | |
"VersionDate": "2019-09-26T18:11:18.107952Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3027, | |
"OrigId": 3027, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T19:10:33.392351Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "if (findloc (c, x, 1) != 0) then", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:10:33.392351Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3041, | |
"OrigId": 3041, | |
"Author": "Erk", | |
"CreationDate": "2019-09-26T19:40:09.778641Z", | |
"LastEditor": "Erk", | |
"LanguageName": "Prolog", | |
"CodeBlock": "member(X, [One]).", | |
"OriginalAttributionURL": "https://www.swi-prolog.org/pldoc/man?predicate=member/2", | |
"DemoURL": "", | |
"DocumentationURL": "https://www.swi-prolog.org/pldoc/man?predicate=member/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:40:09.778641Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3356, | |
"OrigId": 3356, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:09:39.376042Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Dim ItemList As New List(Of String)(New String() {\"one\", \"two\", \"three\"})\nConsole.WriteLine(ItemList.Contains(\"one\"))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:09:39.376042Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3435, | |
"OrigId": 3435, | |
"Author": "spectrum", | |
"CreationDate": "2019-09-28T13:38:23.979362Z", | |
"LastEditor": "spectrum", | |
"LanguageName": "Fortran", | |
"CodeBlock": "if (any(x == list)) ...", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "\"x == list\" returns an array of booleans. any() is true if any element of the argument array is true.", | |
"Version": 1, | |
"VersionDate": "2019-09-28T13:38:23.979362Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 43, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
52 | |
], | |
"RelatedIdiomTitles": [ | |
"Check if map contains value" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 13, | |
"OrigId": 0, | |
"Title": "Iterate over map keys and values", | |
"LeadParagraph": "Print each key _k with its value _x from an associative array _mymap", | |
"ExtraKeywords": "table dictionary hash traverse traversal", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Kotlin implementation by user [miguel]", | |
"LastEditedImplID": 3142, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/13/map-iterate-keys-values.png", | |
"Version": 67, | |
"VersionDate": "2019-09-26T22:49:01.280162Z", | |
"Implementations": [ | |
{ | |
"Id": 54, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "for (Map.Entry\u003cObject, Object\u003e entry : mymap.entrySet()) {\n Object k = entry.getKey();\n Object x = entry.getValue();\n System.out.println(\"Key=\" + k + \", Value=\" + x);\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/1066589/java-iterate-through-hashmap#answer-1066607", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Instead of _Object, prefer using sensible key type and value type for your map.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 55, | |
"OrigId": 55, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "for k, x := range mymap {\n fmt.Println(\"Key =\", k, \", Value =\", x)\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/5BMpuLiuXj", | |
"DocumentationURL": "", | |
"AuthorComment": "Do not rely on the order of the traversal ! The order is undefined and is intentionaly randomized by the Go runtime.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"fmt\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 67, | |
"OrigId": 67, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "nv", | |
"LanguageName": "Ruby", | |
"CodeBlock": "mymap.each {|k, x| puts \"Key= #{k} Value=#{x}\"}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 314, | |
"OrigId": 314, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "while ( ($k,$v) = each %mymap) {\n print \"Key=$k, Value=$v\\n\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 367, | |
"OrigId": 367, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "Object.entries(mymap).forEach(([key, value]) =\u003e {\n\tconsole.log('key:', key, 'value:', value);\n});\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:43:55.1709Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 400, | |
"OrigId": 400, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "Rust", | |
"CodeBlock": "for (key, val) in \u0026mymap {\n println!(\"Key={key}, Value={val}\", key=key, val=val);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/FnGX0Z", | |
"DocumentationURL": "", | |
"AuthorComment": "You can also print collections in a 'nice' way with `println!(\"{:?}\", mymap);` which is the Debug-representation. You can also use \"{:#?}\" for the pretty version.\r\n\r\nThis example works the same if you replace `BTreeMap` with `HashMap`.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::collections::BTreeMap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 416, | |
"OrigId": 416, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "foreach ($mymap as $k=\u003e$x)\n{\n echo \"Key=$k, Value=$x \u003cbr\u003e\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 505, | |
"OrigId": 505, | |
"Author": "bbtemp", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "int[string] mymap = [\"Hello\":1 , \"World\":2];\nforeach (k, v; mymap)\n writeln(\"Key: \", k, \" Value: \", v);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "D has built-in associative array", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.239861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 574, | |
"OrigId": 574, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "sparkiegeek", | |
"LanguageName": "Python", | |
"CodeBlock": "for k, v in mymap.items():\n print(k, v)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:58:43.137592Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 614, | |
"OrigId": 614, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "MaterialTime", | |
"LanguageName": "Dart", | |
"CodeBlock": "mymap.forEach((k, v) =\u003e print('Key=$k, Value=$v'));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/7b1e631229109150ebe96c32d43f3abb", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2019-05-31T20:57:18.986951Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 754, | |
"OrigId": 754, | |
"Author": "Geep Jeez", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "Anonymous", | |
"LanguageName": "Pascal", | |
"CodeBlock": "for i := 1 to mymap.Count \t\tdo\n WriteLn(mymap.Keys[i], '=', mymap.Data[i]);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://wiki.freepascal.org/Generics#fgl_unit", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:18:10.289158Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses fgl;\r\ntype TMyMap = specialize TFPGMap\u003cString, Integer\u003e;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 919, | |
"OrigId": 919, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Enum.each(mymap, fn({k, x}) -\u003e\r\n IO.puts(\"#{k} =\u003e #{x}\")\r\nend)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/c64ac488c1", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/Enum.html#each/2", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-11-20T18:28:26.943095Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 949, | |
"OrigId": 949, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "taktoa", | |
"LanguageName": "Haskell", | |
"CodeBlock": "let f k v = [show k, \" = \", show v]\r\n mapped = Map.mapWithKeys f mymap\r\nin putStrLn $ intercalate \",\" $ mapped", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2016-04-14T15:11:07.722165Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Data.List (intercalate)\r\nimport qualified Data.Map as Map", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1013, | |
"OrigId": 1013, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.239861Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "for {k, x} \u003c- mymap do\r\n IO.puts(\"#{k} =\u003e #{x}\")\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/ff27318cad", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-14T19:02:09.746208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1126, | |
"OrigId": 1126, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T02:58:52.091933Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "maps:fold(\r\n\tfun(K, V, ok) -\u003e\r\n\t\tio:format(\"~p: ~p~n\", [K, V])\r\n\tend, ok, MyMap).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=18f3", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/maps.html?i=0\u0026search=maps:fold#fold/3", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-12-18T02:58:52.091933Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1338, | |
"OrigId": 1338, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T16:58:54.041359Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "for k, x in pairs(mymap) do\r\n\tprint('Key: '..k..', Value: '..x)\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:58:54.041359Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1376, | |
"OrigId": 1376, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T18:28:18.85561Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Cpp", | |
"CodeBlock": "for (const auto\u0026 kv: mymap) {\n\tstd::cout \u003c\u003c \"Key: \" \u003c\u003c kv.first \u003c\u003c \" Value: \" kv.second \u003c\u003c std::endl;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "std::endl flushes stdout.", | |
"Version": 3, | |
"VersionDate": "2019-08-05T16:38:52.463342Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1406, | |
"OrigId": 1406, | |
"Author": "Boris", | |
"CreationDate": "2016-02-16T19:37:33.841917Z", | |
"LastEditor": "Boris", | |
"LanguageName": "Prolog", | |
"CodeBlock": "forall(get_dict(K, D, V),\r\n format(\"~w:~w~n\", [K, V]))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://swish.swi-prolog.org/p/UdBoXLIk.swinb", | |
"DocumentationURL": "swi-prolog.org", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T19:37:33.841917Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1446, | |
"OrigId": 1446, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:53:58.797087Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val x = Map(\"a\" -\u003e 1, \"b\" -\u003e 2, \"c\" -\u003e 3)\r\nx.foreach{ case (key, value) =\u003e println(s\"$key =\u003e $value\")}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:53:58.797087Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1492, | |
"OrigId": 1492, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T10:57:53.501666Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "foreach(var entry in map)\r\n{\r\n Console.WriteLine(\"Key=\" + entry.Key + \", Value=\" + entry.Value);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T10:57:53.501666Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1511, | |
"OrigId": 1511, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T15:40:51.072852Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ada", | |
"CodeBlock": "for C in My_Map.Iterate loop\r\n Put_Line (\"Key = \" \u0026 Key (C) \u0026 \", Value = \" \u0026 Element (C));\r\nend loop;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-02-17T17:10:56.990603Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Containers.Indefinite_Hashed_Maps;\r\nwith Ada.Strings.Hash;\r\n\r\nuse Ada.Containers;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1527, | |
"OrigId": 1527, | |
"Author": "pgon101a", | |
"CreationDate": "2016-02-17T22:55:04.625154Z", | |
"LastEditor": "finalfantasia", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(doseq [[k x] mymap]\n (println k \":\" x))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:21:02.842519Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2675, | |
"OrigId": 2675, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2019-08-05T16:37:33.687269Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Cpp", | |
"CodeBlock": "for (const auto\u0026 [key, value]: mymap) {\n\tstd::cout \u003c\u003c \"Key: \" \u003c\u003c key \u003c\u003c \" Value: \" value \u003c\u003c '\\n';\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://en.cppreference.com/w/cpp/language/structured_binding", | |
"AuthorComment": "The [_key, _value] syntax is a structured binding declaration, since C++17.\r\n\r\n'\\n' doesn't flush stdout.", | |
"Version": 1, | |
"VersionDate": "2019-08-05T16:37:33.687269Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2995, | |
"OrigId": 2995, | |
"Author": "fadamakis", | |
"CreationDate": "2019-09-26T18:04:58.285452Z", | |
"LastEditor": "fadamakis", | |
"LanguageName": "JS", | |
"CodeBlock": "for (const key in mymap) {\n console.log('key:', key, 'value:', mymap[key]);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T18:04:58.285452Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3142, | |
"OrigId": 3142, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T22:49:01.206712Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "mymap.entries.forEach { print(\"${it.key} ${it.value}\") }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:49:01.206712Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 25, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
8, | |
112, | |
113 | |
], | |
"RelatedIdiomTitles": [ | |
"Initialize a new Map (associative array)", | |
"Iterate over map entries, ordered by keys", | |
"Iterate over map entries, ordered by values" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 14, | |
"OrigId": 0, | |
"Title": "Pick uniformly a random floating point number in [a..b[", | |
"LeadParagraph": "Pick a random number greater than or equals to _a, strictly inferior to _b. Precondition : _a \u003c _b.", | |
"ExtraKeywords": "choose", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Python implementation by user [vinodv]", | |
"LastEditedImplID": 3410, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 40, | |
"VersionDate": "2019-09-28T08:37:42.780406Z", | |
"Implementations": [ | |
{ | |
"Id": 57, | |
"OrigId": -1, | |
"Author": "deleplace", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "deleplace", | |
"LanguageName": "Java", | |
"CodeBlock": "double pick(double a, double b){\n\treturn a + (Math.random() * (b-a));\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Math;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 68, | |
"OrigId": 68, | |
"Author": "Otakode", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "double pick(double a, double b)\n{\n\treturn a + (double)rand() / ((double)RAND_MAX * (b - a));\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 94, | |
"OrigId": 94, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "rand(a...b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "(Presuming _a and/or _b are floats) a range constructed using ... excludes the end value.", | |
"Version": 4, | |
"VersionDate": "2016-10-08T21:59:51.856814Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 169, | |
"OrigId": 169, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func pick(a, b float64) float64 {\n\treturn a + (rand.Float64() * (b-a))\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/u9jD263euJ", | |
"DocumentationURL": "https://golang.org/pkg/math/rand/#Float64", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 185, | |
"OrigId": 185, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "nickname", | |
"LanguageName": "Python", | |
"CodeBlock": "def pick(a,b):\n return random.randrange(a, b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/3/library/random.html#random.randrange", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 302, | |
"OrigId": 302, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my ($min, $max) = (1.5, 7.2);\nmy $x = $min + rand($max-$min);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 360, | |
"OrigId": 360, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "a + (b-a) * Math.random();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 526, | |
"OrigId": 526, | |
"Author": "wobbles", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "real pick(real _a, real _b){\n return uniform(_a, _b);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://dlang.org/phobos/std_random.html", | |
"AuthorComment": "This is in the standard library. Use _uniform(_start, _end) to get a number between _start and _end.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 630, | |
"OrigId": 630, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "double pick(num a, num b) =\u003e a + new Random().nextDouble() * (b - a);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/0c5ccdfadcaccabd89c4", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import 'dart:math';", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 659, | |
"OrigId": 659, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "JPSII", | |
"LanguageName": "Pascal", | |
"CodeBlock": "function pick(a, b:real): real;\r\nbegin\r\n result := a + random * (b - a);\r\nend;\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "real can be exchanged with, or set to any other float type like\r\nsingle, double, extended ...", | |
"Version": 2, | |
"VersionDate": "2016-03-21T00:14:02.506462Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 962, | |
"OrigId": 962, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:57.104352Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "pick(a,b)=\n return.(+a).(*(b-a))=\u003c\u003cSystem.Random.randomIO::IO(Double)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.104352Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1553, | |
"OrigId": 1553, | |
"Author": "Marti_2203", | |
"CreationDate": "2016-02-20T17:31:12.289675Z", | |
"LastEditor": "Marti_2203", | |
"LanguageName": "Csharp", | |
"CodeBlock": "double RandomDouble(double a, double b)\r\n{\r\n\tRandom rng=new Random();\r\n \treturn rng.Next(a,b);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-20T17:31:12.289675Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1622, | |
"OrigId": 1622, | |
"Author": "dotvezz", | |
"CreationDate": "2016-03-28T13:33:25.214702Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function pick(float $a, float $b): float\n{\n $rand = mt_rand() / mt_getrandmax();\n $rand *= ($b - $a);\n $rand += ($a);\n\n return $rand;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/function.mt-rand.php", | |
"AuthorComment": "Uses _PHP7 scalar type hinting and return type declaration. This allows for ints to be passed to the function as well.\r\n\r\nUses _mt_rand() instead of rand() for faster generation and uniformity over larger ranges.", | |
"Version": 2, | |
"VersionDate": "2019-09-27T10:17:29.19703Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1689, | |
"OrigId": 1689, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-08T14:01:29.202724Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "function pick(a,b)\r\n\treturn a + (math.random()*(b-a))\r\nend\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.lua.org/manual/5.3/manual.html#pdf-math.random", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-04-08T14:03:33.202479Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1726, | |
"OrigId": 1726, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-06-02T03:35:09.015511Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "A + (B - A) * rand:uniform().", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=6cf3", | |
"DocumentationURL": "http://erldocs.com/maint/stdlib/rand.html?i=8\u0026search=rand:#uniform/0", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-06-02T03:35:09.015511Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1915, | |
"OrigId": 1915, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-11-30T22:03:54.149619Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "a + :rand.uniform() * (b-a)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/2638b2c22f", | |
"DocumentationURL": "http://erlang.org/doc/man/rand.html#uniform-0", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-11-30T22:03:54.149619Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2103, | |
"OrigId": 2103, | |
"Author": "Jerry", | |
"CreationDate": "2017-09-01T16:58:16.782509Z", | |
"LastEditor": "Jerry", | |
"LanguageName": "Clojure", | |
"CodeBlock": " (defn rand-between [a b]\n (+ a (* (- b a) (rand))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-09-01T16:58:16.782509Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2286, | |
"OrigId": 2286, | |
"Author": "Fierthraix", | |
"CreationDate": "2018-04-09T15:01:11.521153Z", | |
"LastEditor": "Fierthraix", | |
"LanguageName": "Rust", | |
"CodeBlock": "thread_rng().gen_range(a, b);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?gist=de0529a8dd7e233f0709fdacf01a57a1\u0026version=stable", | |
"DocumentationURL": "https://doc.rust-lang.org/rand/rand/trait.Rng.html#method.gen_range", | |
"AuthorComment": "If you need to generate a lot of random stuff, save the thread_rng as a variable so it is only initialized once.", | |
"Version": 1, | |
"VersionDate": "2018-04-09T15:01:11.521153Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extern crate rand;\r\nuse rand::{Rng, thread_rng};", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2851, | |
"OrigId": 2851, | |
"Author": "dgd", | |
"CreationDate": "2019-09-26T16:04:48.490806Z", | |
"LastEditor": "dgd", | |
"LanguageName": "Scala", | |
"CodeBlock": "def randomDraw(min: Double, max: Double): Double = {\n val range = max - min\n (random.doubleValue * range) + min\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:04:48.490806Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import math.random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3079, | |
"OrigId": 3079, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:26:12.413965Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "call random_number(c)\nd = a + (b-a) * c", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_c is a temporary variable in [0:1[.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:26:12.413965Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3087, | |
"OrigId": 3087, | |
"Author": "alsi", | |
"CreationDate": "2019-09-26T20:39:55.930198Z", | |
"LastEditor": "alsi", | |
"LanguageName": "JS", | |
"CodeBlock": "a + Math.random() * (b - a)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:39:55.930198Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3106, | |
"OrigId": 3106, | |
"Author": "JonnyH", | |
"CreationDate": "2019-09-26T21:35:41.684488Z", | |
"LastEditor": "JonnyH", | |
"LanguageName": "Cpp", | |
"CodeBlock": "float pick(float a, float b)\n{\n\tstd::default_random_engine generator;\n\tstd::uniform_real_distribution distribution(a, b);\n\treturn distribution(generator);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://godbolt.org/z/wkPkfL", | |
"DocumentationURL": "http://www.cplusplus.com/reference/random/uniform_real_distribution/", | |
"AuthorComment": "You probably want to pass a random engine into the function instead of creating a new one each time in _generator.\r\n\r\nThis example doesn't seed the generator, so will generate the same result in every call.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:35:41.684488Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003crandom\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3150, | |
"OrigId": 3150, | |
"Author": "schnensch", | |
"CreationDate": "2019-09-27T00:26:13.157958Z", | |
"LastEditor": "schnensch", | |
"LanguageName": "Haskell", | |
"CodeBlock": "pick a b = do\n r \u003c- System.Random.randomIO :: IO Double\n return a + (r * (b - a))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T00:26:13.157958Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3337, | |
"OrigId": 3337, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T22:31:17.02718Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Public Function RandomDouble(a As Double, b As Double) As Double\n Dim rng As New Random\n Return rng.Next(a, b)\nEnd Function", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T22:31:17.02718Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "None", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3410, | |
"OrigId": 3410, | |
"Author": "vinodv", | |
"CreationDate": "2019-09-28T08:37:42.776686Z", | |
"LastEditor": "vinodv", | |
"LanguageName": "Python", | |
"CodeBlock": "random.uniform(a,b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-28T08:37:42.776686Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import random", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 25, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
15 | |
], | |
"RelatedIdiomTitles": [ | |
"Pick uniformly a random integer in [a..b]" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 15, | |
"OrigId": 0, | |
"Title": "Pick uniformly a random integer in [a..b]", | |
"LeadParagraph": "Pick a random integer greater than or equals to _a, inferior or equals to _b. Precondition : _a \u003c _b.", | |
"ExtraKeywords": "choose", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [tkoenig]", | |
"LastEditedImplID": 3083, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 41, | |
"VersionDate": "2019-09-26T20:34:09.045256Z", | |
"Implementations": [ | |
{ | |
"Id": 58, | |
"OrigId": -1, | |
"Author": "deleplace", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Java", | |
"CodeBlock": "int pick(int a, int b){\n\treturn a + new Random().nextInt(b - a + 1);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "For performance, consider reusing the Random object.\r\n\r\n(b-a+1) is needed to have upper bound _b included.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Random;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 69, | |
"OrigId": 69, | |
"Author": "Otakode", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "daniel", | |
"LanguageName": "C", | |
"CodeBlock": "int pick(int a, int b)\n{\n\tint upper_bound = b - a + 1;\n\tint max = RAND_MAX - RAND_MAX % upper_bound;\n\tint r;\n\n\tdo {\n\t\tr = rand();\n\t} while (r \u003e= max);\n\tr = r % max;\n\treturn a + r;\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://stackoverflow.com/a/10984975/4087179", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:12:46.181696Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 95, | |
"OrigId": 95, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "rand(a..b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-04-07T20:27:01.008443Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 168, | |
"OrigId": 168, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func pick(a,b int) int {\n\treturn a + rand.Intn(b-a+1)\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/Tk1Gl2sxv-", | |
"DocumentationURL": "https://golang.org/pkg/math/rand/#Intn", | |
"AuthorComment": "(b-a+1) is needed to have upper bound _b included.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"math/rand\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 170, | |
"OrigId": 170, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "JS", | |
"CodeBlock": "function pick(a, b) {\n return a + Math.floor(Math.random() * (b - a + 1));\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/10134261/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "You have to build it from a floating-point random number. It is important to use _floor , not _round .", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 184, | |
"OrigId": 184, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "random.randint(a,b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Upper bound _b is included.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 234, | |
"OrigId": 234, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "rand($a, $b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/function.rand.php", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 258, | |
"OrigId": 258, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scala", | |
"CodeBlock": "a + Random.nextInt(b + 1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import util.Random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 295, | |
"OrigId": 295, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my ($min, $max) = (5, 25);\nmy $val = $min + int(rand($max-$min));\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 501, | |
"OrigId": 501, | |
"Author": "ehiggs", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "ehiggs", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn pick(a: i32, b: i32) -\u003e i32 {\n let between = Range::new(a, b);\n let mut rng = rand::thread_rng();\n between.ind_sample(\u0026mut rng)\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extern crate rand;\r\nuse rand::distributions::{IndependentSample, Range};", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 524, | |
"OrigId": 524, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "schveiguy", | |
"LanguageName": "D", | |
"CodeBlock": "auto x1 = uniform(a, b+1);\nauto x2 = uniform!\"[]\"(a, b);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "default boundaries for uniform are exclusive of upper bound, but can be configured as shown for 'x2' example.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.random;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 605, | |
"OrigId": 605, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "int pick(int a, int b) =\u003e a + new Random().nextInt(b - a + 1);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/c45bb7de8d83dd80e37e", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import 'dart:math';", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 706, | |
"OrigId": 706, | |
"Author": "Bart", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "Bart", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var\n _a, _b, _r: Integer;\nbegin\n _r := RandomRange(_a, _b);\nend; ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "Math", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 784, | |
"OrigId": 784, | |
"Author": "NoTel", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "NoTel", | |
"LanguageName": "Erlang", | |
"CodeBlock": "crypto:rand_uniform(A, B)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erlang.org/doc/man/crypto.html#rand_uniform-2", | |
"AuthorComment": "Variables in Erlang must begin with capitals.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 812, | |
"OrigId": 812, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "let pick (a, b) = randomRIO (a, b) :: IO Integer\n in pick (1, 6) \u003e\u003e= print\n\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/random/docs/System-Random.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import System.Random", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 820, | |
"OrigId": 820, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "( + a (rand-int (- b a)))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/rand-int", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 985, | |
"OrigId": 985, | |
"Author": "hashd", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": ":crypto.rand_uniform(a, b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/2030d98a44", | |
"DocumentationURL": "http://erlang.org/doc/man/crypto.html#rand_uniform-2", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-02-07T21:45:31.106234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1324, | |
"OrigId": 1324, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "math.random(a, b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Be sure to do math.randomseed(os.time()) or something equivalent somewhere up above.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.20109Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1358, | |
"OrigId": 1358, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-18T16:57:57.20109Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Random r = new Random();\r\nreturn r.next(a, b + 1);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://msdn.microsoft.com/en-us/library/system.random%28v=vs.110%29.aspx", | |
"AuthorComment": "Make sure to add 1 to the second argument of _next, as it is not inclusive by default.", | |
"Version": 2, | |
"VersionDate": "2017-03-07T10:31:09.324324Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1914, | |
"OrigId": 1914, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-11-30T21:58:42.877532Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "a - 1 + :rand.uniform(b-a+1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/c609a6bb54", | |
"DocumentationURL": "http://erlang.org/doc/man/rand.html#uniform-1", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T22:01:52.986496Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2310, | |
"OrigId": 2310, | |
"Author": "fantasy", | |
"CreationDate": "2018-05-08T01:28:15.447024Z", | |
"LastEditor": "fantasy", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::mt19937 gen;\nstd::uniform_int_distribution\u003csize_t\u003e uid (a, b);\nuid (gen);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-05-08T01:28:15.447024Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003crandom\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3083, | |
"OrigId": 3083, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:34:09.042373Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "real :: c\ninteger :: res\n\ncall random_number(c)\nres = int((b-a+1)*c)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:34:09.042373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 22, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
14 | |
], | |
"RelatedIdiomTitles": [ | |
"Pick uniformly a random real number in [a..b[" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 16, | |
"OrigId": 0, | |
"Title": "Depth-first traversing of a binary tree", | |
"LeadParagraph": "Call a function _f on every node of binary tree _bt, in depth-first infix order", | |
"ExtraKeywords": "dfs", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New JS implementation by user [devbg]", | |
"LastEditedImplID": 2450, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 34, | |
"VersionDate": "2018-11-09T13:41:37.362849Z", | |
"Implementations": [ | |
{ | |
"Id": 76, | |
"OrigId": -1, | |
"Author": "deleplace", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func (bt *BinTree) Dfs(f func(*BinTree)) {\r\n\tif bt == nil {\r\n\t\treturn\r\n\t}\r\n\tbt.Left.Dfs(f)\r\n\tf(bt)\r\n\tbt.Right.Dfs(f)\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/CbxBgThIUf", | |
"DocumentationURL": "", | |
"AuthorComment": "The function _f is a parameter of the traversal method _Dfs.\r\nIt's legit to call a method on a _nil receiver, and useful to make code more concise with less checks for nil.", | |
"Version": 3, | |
"VersionDate": "2016-04-28T11:48:25.182032Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 354, | |
"OrigId": 354, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub dfs {\n my ($f, $bt) = @_;\n dfs($f, $bt-\u003e{left}) if exists $bt-\u003e{left};\n $f-\u003e($bt);\n dfs($f, $bt-\u003e{right}) if exists $bt-\u003e{right};\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.503503Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 649, | |
"OrigId": 649, | |
"Author": "cym13", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "cym13", | |
"LanguageName": "D", | |
"CodeBlock": "void btTraversal(T)(BinaryTree!T bt, void function(T) f) {\n if (bt.left)\n btTraversal(*(bt.left), f);\n\n f(bt.data);\n\n if (bt.right)\n btTraversal(*(bt.right), f);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.503503Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 743, | |
"OrigId": 743, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "traverse(Node bt, f(value)) {\n if (bt == null) return;\n traverse(bt.left, f);\n f(bt.value);\n traverse(bt.right, f);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.503503Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 884, | |
"OrigId": 884, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def dfs(f, bt)\n dfs(f, bt.left) if bt.left\n f.(bt)\n dfs(f, bt.right if bt.right\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.503503Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 992, | |
"OrigId": 992, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:26.503503Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "inorder Ø = []\ninorder (BT left pivot right) =\n inorder left ++ pivot : inorder right\nf \u003c$\u003e inorder bt\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.503503Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1508, | |
"OrigId": 1508, | |
"Author": "ara", | |
"CreationDate": "2016-02-17T12:08:34.344039Z", | |
"LastEditor": "ara", | |
"LanguageName": "Haskell", | |
"CodeBlock": "instance Functor BT where\r\n fmap f (BT l x r) = BT (fmap f l) (f x) (fmap f r)\r\n\r\nfmap f bt", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T12:08:34.344039Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1530, | |
"OrigId": 1530, | |
"Author": "TinyFawks", | |
"CreationDate": "2016-02-18T08:50:27.130406Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "def dfs(bt):\r\n\tif bt is None:\r\n\t\treturn\r\n\tdfs(bt.left)\r\n\tf(bt)\r\n\tdfs(bt.right)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Recursive DFS.", | |
"Version": 2, | |
"VersionDate": "2016-02-18T09:16:52.625429Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1624, | |
"OrigId": 1624, | |
"Author": "agilla1", | |
"CreationDate": "2016-03-29T12:55:19.117175Z", | |
"LastEditor": "agilla1", | |
"LanguageName": "PHP", | |
"CodeBlock": "public function dfs($f, $bt)\r\n{\r\n\tif ($bt-\u003eleft != null)\r\n\t\t$this-\u003edfs($f, $bt-\u003eleft);\r\n\r\n\t$f($bt);\r\n\t\r\n\tif ($bt-\u003eright != null)\r\n\t\t$this-\u003edfs($f, $bt-\u003eright);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-03-29T12:55:42.23174Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1919, | |
"OrigId": 1919, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-12-04T21:34:04.230833Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "void dfs(BinTree bt) {\r\n\tif( bt.left != nil )\r\n\t\tdfs(bt.left);\r\n\tf(bt);\r\n\tif( bt.right != nil )\r\n\t\tdfs(bt.right);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Here, the call to _f is hard-coded, we can't specify _f as a parameter.", | |
"Version": 1, | |
"VersionDate": "2016-12-04T21:34:04.230833Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1920, | |
"OrigId": 1920, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-12-04T21:36:37.332395Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "class BinTree {\r\n\t// ...\r\n\r\n\tvoid dfs() {\r\n\t\tif( left != nil )\r\n\t\t\tleft.dfs();\r\n\t\tf(this);\r\n\t\tif( right != nil )\r\n\t\t\tright.dfs();\r\n\t}\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_dfs is a method.\r\n\r\nHere, the call to _f is hard-coded, we can't specify _f as a parameter.", | |
"Version": 1, | |
"VersionDate": "2016-12-04T21:36:37.332395Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1921, | |
"OrigId": 1921, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-12-04T22:13:01.156501Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "class BinTree\u003cT\u003e {\r\n\t// ...\r\n\r\n\tvoid dfs(Consumer\u003cBinTree\u003cT\u003e\u003e f) {\r\n\t\tif( left != null )\r\n\t\t\tleft.dfs(f);\r\n\t\tf.accept(this);\r\n\t\tif( right != null )\r\n\t\t\tright.dfs(f);\r\n\t}\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/26jbHx", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html", | |
"AuthorComment": "This works in java \u003e= 8.\r\n\r\n_dfs is a method.\r\n\r\n_f is functional argument.", | |
"Version": 1, | |
"VersionDate": "2016-12-04T22:13:01.156501Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.function.Consumer;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2024, | |
"OrigId": 2024, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-12T15:32:45.646447Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (map-btree f bt)\n (if (not (null? bt))\n (make-btree (f (btree-value bt))\n (map-btree f (btree-left bt))\n (map-btree f (btree-right bt)))\n bt))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "See binary tree definition in idiom 9.", | |
"Version": 2, | |
"VersionDate": "2017-06-12T15:35:39.189789Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2450, | |
"OrigId": 2450, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T13:41:37.359843Z", | |
"LastEditor": "devbg", | |
"LanguageName": "JS", | |
"CodeBlock": "function dfs(bt) {\n\tif (bt === undefined) return;\n\tdfs(bt.left);\n\tf(bt);\n\tdfs(bt.right);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-11-09T13:41:37.359843Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 14, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
9, | |
18 | |
], | |
"RelatedIdiomTitles": [ | |
"Create a Binary Tree data structure", | |
"Depth-first traversing of a tree" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 17, | |
"OrigId": 0, | |
"Title": "Create a Tree data structure", | |
"LeadParagraph": "The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Rust] The size of `Node` must be known at compile time.", | |
"LastEditedImplID": 1930, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 44, | |
"VersionDate": "2019-09-27T22:18:43.617537Z", | |
"Implementations": [ | |
{ | |
"Id": 77, | |
"OrigId": -1, | |
"Author": "deleplace", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "type Tree struct {\r\n\tKey keyType\r\n\tDeco valueType\r\n\tChildren []*Tree\r\n}\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/uYALlGxGjf", | |
"DocumentationURL": "", | |
"AuthorComment": "_keyType should be easily comparable.\r\n_valueType is a type of value associated with current node.\r\n_Children is a slice of pointers.\r\n\r\nNote that in Go you can call methods of pointer type *Tree even on a _nil receiver (an empty tree).", | |
"Version": 3, | |
"VersionDate": "2016-12-04T21:20:29.733641Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 531, | |
"OrigId": 531, | |
"Author": "wobbles", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "struct Node(T){\n Node[] children;\n T data;\n}\n\nalias TreeOfIntegers = Node!(int);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Inside template Node(T), _Node is an alias for the instantiated type.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.310492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 744, | |
"OrigId": 744, | |
"Author": "LRHN", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "class Node\u003cT\u003e {\n final T value;\n final List\u003cNode\u003cT\u003e\u003e children;\n Node(this.value, this.children);\n}\n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.310492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 751, | |
"OrigId": 751, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type\n TTree = class\n Children: array of TTree;\n Data: TObject;\n end; ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.310492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 752, | |
"OrigId": 752, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type\ngeneric\n TTree\u003c_T\u003e = class(TObject)\n Children: array of TObject;\n Data: _T;\n end;\n\ntype\n TStringTree = specialize TTree\u003cString\u003e;\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This Example uses generics\r\n", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.310492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 788, | |
"OrigId": 788, | |
"Author": "alexv19", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "alexv19", | |
"LanguageName": "Haskell", | |
"CodeBlock": "data Tree a = Node {\n value :: a,\n children :: [Tree a]\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.310492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 885, | |
"OrigId": 885, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "Node = Struct.new(:children)\nparent = Node.new([])\nparent.children \u003c\u003c Node.new([])", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.310492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1103, | |
"OrigId": 1103, | |
"Author": "nickname", | |
"CreationDate": "2016-02-18T16:57:57.310492Z", | |
"LastEditor": "hnhn", | |
"LanguageName": "Python", | |
"CodeBlock": "class Node(object):\n def __init__(self, value, *children):\n self.value = value\n self.children = list(children)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-10-04T20:22:26.702125Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1555, | |
"OrigId": 1555, | |
"Author": "Marti_2203", | |
"CreationDate": "2016-02-20T17:39:11.55451Z", | |
"LastEditor": "AllanDeutsch", | |
"LanguageName": "Csharp", | |
"CodeBlock": "class Node\u003cT\u003e\r\n{\r\n T value;\r\n List\u003cNode\u003cT\u003e\u003e childNodes;\r\n}\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The _Children can be stored in an _Array or _List, depending on how you want to implement it.", | |
"Version": 2, | |
"VersionDate": "2016-05-11T17:55:53.742723Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System.Collections.Generic", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1718, | |
"OrigId": 1718, | |
"Author": "AllanDeutsch", | |
"CreationDate": "2016-05-16T22:00:45.147537Z", | |
"LastEditor": "AllanDeutsch", | |
"LanguageName": "Cpp", | |
"CodeBlock": "template\u003ctypename T\u003e\r\nstruct Node{\r\n T value;\r\n std::vector\u003cNode\u003cT\u003e\u003e children;\r\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-05-16T22:02:27.029678Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cvector\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1917, | |
"OrigId": 1917, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-12-04T21:17:10.676254Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "class Tree\u003cK,V\u003e {\r\n K key;\r\n V deco;\r\n List\u003cTree\u003cK,V\u003e\u003e children = new ArrayList\u003c\u003e();\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/g8aQaj", | |
"DocumentationURL": "", | |
"AuthorComment": "Then you will want to add constructors, getters, setters.", | |
"Version": 1, | |
"VersionDate": "2016-12-04T21:17:10.676254Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.List;\r\nimport java.util.ArrayList;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1930, | |
"OrigId": 1930, | |
"Author": "sphinxc0re", | |
"CreationDate": "2016-12-13T20:58:15.563768Z", | |
"LastEditor": "Worik", | |
"LanguageName": "Rust", | |
"CodeBlock": "struct Node\u003cT\u003e {\n value: T,\n children: Vec\u003cBox\u003cNode\u003cT\u003e\u003e\u003e,\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Must be boxed. Size must be known at compile time", | |
"Version": 2, | |
"VersionDate": "2019-09-27T22:18:43.614777Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2002, | |
"OrigId": 2002, | |
"Author": "Dodopod", | |
"CreationDate": "2017-05-27T20:12:09.624318Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "C", | |
"CodeBlock": "typedef struct node_s\n{\n int value;\n struct node_s *nextSibling;\n struct node_s *firstChild;\n} node_t;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-05-27T20:12:09.624318Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2026, | |
"OrigId": 2026, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-12T15:38:52.475698Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (make-tree value children)\n (cons value children))\n\n(define (tree-value t) (car t))\n(define (tree-first-child t) (cadr t))\n(define (tree-rest-children t) (cddr t))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_children is list of _trees", | |
"Version": 1, | |
"VersionDate": "2017-06-12T15:38:52.475698Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2263, | |
"OrigId": 2263, | |
"Author": "Kng", | |
"CreationDate": "2018-04-03T08:28:06.973421Z", | |
"LastEditor": "Kng", | |
"LanguageName": "Lua", | |
"CodeBlock": "local function Tree(v, c)\n\treturn {\n\t\tval = v,\n\t\tchildren = c\n\t}\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-04-03T08:28:06.973421Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2409, | |
"OrigId": 2409, | |
"Author": "ricardo_sdl", | |
"CreationDate": "2018-08-29T20:41:05.757725Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "class Tree\n{\n public $children = [];\n public $data;\n \n public function __construct($data, $children)\n {\n $this-\u003edata = $data;\n $this-\u003echildren = $children;\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/GIgDC", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T10:18:08.847561Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2522, | |
"OrigId": 2522, | |
"Author": "1.7.4", | |
"CreationDate": "2019-01-23T17:35:06.227599Z", | |
"LastEditor": "1.7.4", | |
"LanguageName": "JS", | |
"CodeBlock": "class Node {\n constructor (value, children = []) {\n this.value = value\n this.children = children\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-01-23T17:35:06.227599Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2776, | |
"OrigId": 2776, | |
"Author": "Lynx", | |
"CreationDate": "2019-09-26T15:00:31.932836Z", | |
"LastEditor": "Lynx", | |
"LanguageName": "Scala", | |
"CodeBlock": "case class Node[T](value: T, children: List[Node[T]] = Nil)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:00:31.932836Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2925, | |
"OrigId": 2925, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T17:05:52.79534Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "type 'a Tree = {\n\tvalue: 'a;\n\tchildren: 'a tree list;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:07:24.245058Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3061, | |
"OrigId": 3061, | |
"Author": "foo", | |
"CreationDate": "2019-09-26T19:52:40.514427Z", | |
"LastEditor": "foo", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $tree = {\n 'Root' =\u003e {\n 'Child1' =\u003e {\n 'GrandChild1' =\u003e {},\n 'GrandChild2' =\u003e {}\n },\n 'Child2' =\u003e {}\n }\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The natural way to create a tree in perl is using hash references.\r\n\r\nJust declare it!\r\n\r\nTo add a new item:\r\n\r\n$tree-\u003e{Root}-\u003e{Child2}-\u003e{GrandChild3} = {};", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:52:40.514427Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3209, | |
"OrigId": 3209, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T08:50:51.747066Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "type node_t\n integer:: value\n type(node_s), pointer :: next_sibling;\n type(node_s), pointer :: first_child;\nend type node_t", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T08:50:51.747066Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 21, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
18, | |
128, | |
9 | |
], | |
"RelatedIdiomTitles": [ | |
"Depth-first traversing of a tree", | |
"Breadth-first traversing of a tree", | |
"Create a Binary Tree data structure" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 18, | |
"OrigId": 0, | |
"Title": "Depth-first traversing of a tree", | |
"LeadParagraph": "Call a function _f on every node of a tree, in depth-first prefix order", | |
"ExtraKeywords": "dfs", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New PHP implementation by user [jesusflores.dev]", | |
"LastEditedImplID": 2752, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/18/tree_dfs.png", | |
"Version": 35, | |
"VersionDate": "2019-09-26T14:38:59.31447Z", | |
"Implementations": [ | |
{ | |
"Id": 78, | |
"OrigId": -1, | |
"Author": "deleplace", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func (t *Tree) Dfs(f func(*Tree)) {\r\n\tif t == nil {\r\n\t\treturn\r\n\t}\r\n\tf(t)\r\n\tfor _, child := range t.Children {\r\n\t\tchild.Dfs(f)\r\n\t}\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/o6OYsiEHl6", | |
"DocumentationURL": "", | |
"AuthorComment": "The function _f is a parameter of the traversal method _Dfs .\r\nThe traversal is prefix because _f is applied to current node first.", | |
"Version": 5, | |
"VersionDate": "2016-05-01T22:25:45.223358Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 335, | |
"OrigId": 335, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub depth_first_traversal {\r\n my ($f, $treenode) = @_;\r\n $f-\u003e($treenode);\r\n depth_first_traversal($f, $_) for @{$treenode-\u003e{children}};\r\n}\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Assumes the tree is built from a hash, where the children property contains the current nodes children.", | |
"Version": 2, | |
"VersionDate": "2016-11-04T11:27:34.234909Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 528, | |
"OrigId": 528, | |
"Author": "jwhear", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "jwhear", | |
"LanguageName": "D", | |
"CodeBlock": "void prefixOrderTraversal(alias f)(ref Tree tree)\n{\n\tf(tree);\n\tforeach (child; tree.children)\n\t\tprefixOrderTraversal!f(child);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This version takes _f as a compile-time parameter, allowing inlining and other optimizations.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.349224Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 587, | |
"OrigId": 587, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "pub struct Tree\u003cV\u003e {\n children: Vec\u003cTree\u003cV\u003e\u003e,\n value: V\n}\n\nimpl\u003cV\u003e Tree\u003cV\u003e {\n pub fn dfs\u003cF: Fn(\u0026V)\u003e(\u0026self, f: F) {\n self.dfs_helper(\u0026f);\n }\n fn dfs_helper\u003cF: Fn(\u0026V)\u003e(\u0026self, f: \u0026F) {\n (f)(\u0026self.value);\n for child in \u0026self.children {\n child.dfs_helper(f)\n }\n }\n // ...\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The actual idiomatic way to do this is to implement an iterator.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.349224Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 719, | |
"OrigId": 719, | |
"Author": "lrhn", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "lrhn", | |
"LanguageName": "Dart", | |
"CodeBlock": "traverse(Tree node, f(value)) {\n f(node.value);\n for (var child in node.children) { \n traverse(child, f);\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.349224Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 887, | |
"OrigId": 887, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def dfs(f, node)\r\n f.(node)\r\n node.children.each do |child|\r\n dfs(f, child)\r\n end\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-04T11:28:18.925867Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 984, | |
"OrigId": 984, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:57.349224Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "preordered (Node pivot left right) = \n pivot : preordered left ++ preordered right\npreordered Ø = []\nf \u003c$\u003e (preordered tree)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.349224Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2084, | |
"OrigId": 2084, | |
"Author": "cpoulet_42", | |
"CreationDate": "2017-08-09T09:20:28.30958Z", | |
"LastEditor": "cpoulet_42", | |
"LanguageName": "Python", | |
"CodeBlock": "def DFS(f, root):\n\tf(root)\n\tfor child in root:\n\t\tDFS(f, child)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-08-09T09:21:46.384451Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2451, | |
"OrigId": 2451, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T13:49:26.052829Z", | |
"LastEditor": "devbg", | |
"LanguageName": "JS", | |
"CodeBlock": "function DFS(f, root) {\n\tf(root)\n\tif (root.children) {\n\t\troot.children.forEach(child =\u003e DFS(f, child))\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "es6 version", | |
"Version": 1, | |
"VersionDate": "2018-11-09T13:49:26.052829Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2752, | |
"OrigId": 2752, | |
"Author": "jesusflores.dev", | |
"CreationDate": "2019-09-26T14:38:59.311633Z", | |
"LastEditor": "jesusflores.dev", | |
"LanguageName": "PHP", | |
"CodeBlock": "function dfs($f, $root)\n{\n $f($root);\n foreach($root as $child)\n {\n dfs($child);\n }\t\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Here _dfs is a recursive function to traverse the tree applying a function sent as the _$f parameter", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:38:59.311633Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 10, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
16, | |
128, | |
17, | |
130 | |
], | |
"RelatedIdiomTitles": [ | |
"Depth-first traversing of a binary tree", | |
"Breadth-first traversing of a tree", | |
"Create a Tree data structure", | |
"Depth-first traversing in a graph" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 19, | |
"OrigId": 0, | |
"Title": "Reverse a list", | |
"LeadParagraph": "Reverse the order of the elements of list _x .\r\nThis may reverse \"in-place\" and destroy the original ordering.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New VB implementation by user [EvilGenius]", | |
"LastEditedImplID": 3365, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 52, | |
"VersionDate": "2019-09-27T23:17:59.462789Z", | |
"Implementations": [ | |
{ | |
"Id": 79, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "static \u003cT\u003e void reverse(List\u003cT\u003e x){\n\tint n = x.size();\n\tfor(int i=0;i\u003cn/2;i++){\n\t\tT tmp = x.get(i);\n\t\tx.set(i, x.get(n-i-1));\n\t\tx.set(n-i-1, tmp);\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/kxgipq", | |
"DocumentationURL": "", | |
"AuthorComment": "This method works for lists of any element type _T .\r\n\r\nIn case of an odd number of elements, the central element doesn't need to be swapped.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.List;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 93, | |
"OrigId": 93, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "nv", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x.reverse!", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Reverses self in place.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 197, | |
"OrigId": 197, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "nickname", | |
"LanguageName": "Python", | |
"CodeBlock": "x = reversed(x)", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/3940137/871134", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/3/library/functions.html#reversed", | |
"AuthorComment": "returns an iterable.\r\non lists this creates a new list.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 213, | |
"OrigId": 213, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "reverse(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://dlang.org/phobos/std_algorithm.html#reverse", | |
"AuthorComment": "Reverses _x in-place.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 214, | |
"OrigId": 214, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "for i, j := 0, len(x)-1; i \u003c j; i, j = i+1, j-1 {\n\tx[i], x[j] = x[j], x[i]\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/19239850/871134", | |
"DemoURL": "http://play.golang.org/p/vkJg_D1yUb", | |
"DocumentationURL": "", | |
"AuthorComment": "This loop reverts \"in-place\" (in the original list, not creating a new one).", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 225, | |
"OrigId": 225, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "Collections.reverse(x);", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/10766502/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Collections;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 248, | |
"OrigId": 248, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "$x = array_reverse($x, true);", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/10028273/reverse-array-in-php", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_array_reverse creates a new array.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 298, | |
"OrigId": 298, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my @list = ('words', 'of', 'list', 'a', 'reverse');\nmy @reversed = reverse @list;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "reverse is a built-in function. Given an array, it will reverse it. Given a string, it will return a string with the letters reversed.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 357, | |
"OrigId": 357, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "justafoo", | |
"LanguageName": "JS", | |
"CodeBlock": "x = x.reverse();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse", | |
"AuthorComment": "note that Array.prototype.reverse() not only returns the reversed array, it works _in _place!", | |
"Version": 2, | |
"VersionDate": "2019-09-26T18:23:15.478574Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 444, | |
"OrigId": 444, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let y: Vec\u003c_\u003e = x.iter().rev().collect();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/kzJbJp", | |
"DocumentationURL": "", | |
"AuthorComment": "Instead of _Vec, you can also use any other data structure that implements _collect.", | |
"Version": 2, | |
"VersionDate": "2016-11-29T22:40:52.52941Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 546, | |
"OrigId": 546, | |
"Author": "Meta", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "Meta", | |
"LanguageName": "D", | |
"CodeBlock": "auto y = x.retro;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://dpaste.dzfl.pl/ebf4256b37c4", | |
"DocumentationURL": "", | |
"AuthorComment": "This doesn't allocate a new list or modify the original, but creates an iterator that traverses the list in reverse order.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.range;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 606, | |
"OrigId": 606, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "x.reversed.toList()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/65963208b012e7759d1b", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 660, | |
"OrigId": 660, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var n,i: integer;\n[...]\nn:= length(x);\nsetlength(x, n+1);\nfor i := 0 to (n div 2)-1 do\n\tbegin\n\t\tx[n] := x[i];\n\t\tx[i] := x[n-i-1];\n\t\tx[n-i-1] := x[n];\n\tend;\nsetlength(x, n);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The reversing is done \"in Place\"\r\nexcept one extra element, so it works with any element-type. ", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 661, | |
"OrigId": 661, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var n,i: integer;\n\ttmp:TElement;\n[...]\nn:= length(x);\nfor i := 0 to (n div 2)-1 do\n\tbegin\n\t\ttmp := x[i];\n\t\tx[i] := x[n-i-1];\n\t\tx[n-i-1] := tmp;\n\tend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "alternative implementation, if the type of the elements is known.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 813, | |
"OrigId": 813, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "reverse x\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Prelude.html#v:reverse", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 819, | |
"OrigId": 819, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "lists:reverse(List)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://www.tryerlang.org", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=0\u0026search=lists:rever#reverse/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 823, | |
"OrigId": 823, | |
"Author": "jfacorro", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(reverse x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/reverse", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 912, | |
"OrigId": 912, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:26.805864Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Enum.reverse(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/4240ea9fe1", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/Enum.html#reverse/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.805864Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1314, | |
"OrigId": 1314, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T15:53:56.444232Z", | |
"LastEditor": "ttmrichter", | |
"LanguageName": "Lua", | |
"CodeBlock": "rev = {}\nfor i=#x, 1, -1 do\n\trev[#rev+1] = x[i]\nend\n\n-- in-situ reversal\nfunction reverse(t)\n local n = #t\n local i = 1\n while i \u003c n do\n t[i],t[n] = t[n],t[i]\n i = i + 1\n n = n - 1\n end\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-06-06T08:05:10.507504Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1353, | |
"OrigId": 1353, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-16T17:42:56.360518Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "x.Reverse();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://msdn.microsoft.com/en-us/library/b0axc2h2%28v=vs.110%29.aspx", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:42:56.360518Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "System.Collections.Generic;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1359, | |
"OrigId": 1359, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T17:58:14.805786Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::reverse(begin(x), end(x));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/algorithm/reverse", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:58:14.805786Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003calgorithm\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1439, | |
"OrigId": 1439, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:39:14.221198Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val items = List(1, 2, 3, 4, 5)\r\nitems.reverse", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:39:14.221198Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1516, | |
"OrigId": 1516, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T16:28:45.618288Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "X.Reverse_Elements;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T16:28:45.618288Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Containers.Vectors;\r\nuse Ada.Containers;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1983, | |
"OrigId": 1983, | |
"Author": "synapton", | |
"CreationDate": "2017-05-14T03:47:52.643616Z", | |
"LastEditor": "sgdpk", | |
"LanguageName": "Python", | |
"CodeBlock": "y = x[::-1]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/2.3/whatsnew/section-slices.html", | |
"AuthorComment": "Creates a new, reversed list.", | |
"Version": 3, | |
"VersionDate": "2019-09-27T02:57:37.321491Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1994, | |
"OrigId": 1994, | |
"Author": "Dodopod", | |
"CreationDate": "2017-05-27T19:05:34.046765Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "C", | |
"CodeBlock": "int *p1 = x;\nint *p2 = x + N-1;\n\nwhile (p1 \u003c p2)\n{\n int temp = *p1;\n *(p1++) = *p2;\n *(p2--) = temp;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Reverses an array of _N _ints, in-place.", | |
"Version": 1, | |
"VersionDate": "2017-05-27T19:05:34.046765Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2022, | |
"OrigId": 2022, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-09T15:30:17.810248Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(reverse x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-09T15:30:17.810248Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2181, | |
"OrigId": 2181, | |
"Author": "mitosis", | |
"CreationDate": "2017-11-23T02:47:28.75073Z", | |
"LastEditor": "mitosis", | |
"LanguageName": "Elixir", | |
"CodeBlock": "list = [1, 2, 3, 4, 5]\nEnum.reverse(list)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-11-23T02:47:28.75073Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2249, | |
"OrigId": 2249, | |
"Author": "wobray", | |
"CreationDate": "2018-03-12T05:24:31.819641Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(reverse x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This preserves the value of _x.", | |
"Version": 3, | |
"VersionDate": "2018-03-13T22:16:34.603672Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2331, | |
"OrigId": 2331, | |
"Author": "GobbleCock", | |
"CreationDate": "2018-06-11T19:36:54.162351Z", | |
"LastEditor": "ThePythonicCow", | |
"LanguageName": "Rust", | |
"CodeBlock": "x.reverse();", | |
"OriginalAttributionURL": "https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#examples-5", | |
"DemoURL": "https://play.rust-lang.org/?gist=288d534d236a3e01f27858ead009d988\u0026version=stable\u0026mode=debug", | |
"DocumentationURL": "https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#method.reverse", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2018-08-28T14:46:04.108661Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2891, | |
"OrigId": 2891, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T16:47:29.530199Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "List.rev x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:47:29.530199Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2941, | |
"OrigId": 2941, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:19:56.726337Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "mutableListOrArray.reverse()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "MutableLists or Arrays can be reversed in place. ", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:24:07.645465Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2951, | |
"OrigId": 2951, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:26:50.849017Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val reversedList = list.reversed()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Immutable lists but not in-place.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:26:50.849017Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2986, | |
"OrigId": 2986, | |
"Author": "int64", | |
"CreationDate": "2019-09-26T17:53:47.225963Z", | |
"LastEditor": "int64", | |
"LanguageName": "Java", | |
"CodeBlock": "Collections.reverse(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/Collections.html#reverse(java.util.List)", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:53:47.225963Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Collections;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3050, | |
"OrigId": 3050, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T19:44:43.711721Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " a = a(ubound(a)::-1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T08:29:06.023645Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3164, | |
"OrigId": 3164, | |
"Author": "sgdpk", | |
"CreationDate": "2019-09-27T02:50:36.390766Z", | |
"LastEditor": "sgdpk", | |
"LanguageName": "Python", | |
"CodeBlock": "x.reverse()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Reverses list in place", | |
"Version": 2, | |
"VersionDate": "2019-09-27T02:54:21.628364Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3365, | |
"OrigId": 3365, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:17:59.457303Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Dim ItemList As New List(Of String)(New String() {\"one\", \"two\", \"three\"})\nItemList.Reverse()\nFor Each item In ItemList\n Console.WriteLine(item)\nNext", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:17:59.457303Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 36, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
41 | |
], | |
"RelatedIdiomTitles": [ | |
"Reverse a string" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 20, | |
"OrigId": 0, | |
"Title": "Return two values", | |
"LeadParagraph": "Implement a function _search which looks for item _x in a 2D matrix _m.\r\nReturn indices _i, _j of the matching cell.\r\nThink of the most idiomatic way in the language to return the two values at the same time.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[PHP] Format code snippet to PSR-12", | |
"LastEditedImplID": 1576, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 61, | |
"VersionDate": "2019-09-27T08:58:32.122727Z", | |
"Implementations": [ | |
{ | |
"Id": 115, | |
"OrigId": 115, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func search(m [][]int, x int) (bool, int, int) {\r\n\tfor i := range m {\r\n\t\tfor j, v := range m[i] {\r\n\t\t\tif v == x {\r\n\t\t\t\treturn true, i, j\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn false, 0, 0\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/wFqwygbLje", | |
"DocumentationURL": "", | |
"AuthorComment": "Go functions may return multiple values.\r\nThis function returns 3 values : one to indicate if _x was found or not, and two for the coordinates.", | |
"Version": 2, | |
"VersionDate": "2016-02-20T23:33:38.519529Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 116, | |
"OrigId": 116, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "static class Position{\n\tint i;\n\tint j;\n}\n\nPosition search(int[][] m, int x){\n\tfor(int i=0;i\u003cm.length;i++)\n\t\tfor(int j=0;j\u003cm[i].length;j++)\n\t\t\tif(m[i][j] == x){\n\t\t\t\tPosition pos= new Position();\n\t\t\t\tpos.i = i;\n\t\t\t\tpos.j = j;\n\t\t\t\treturn pos;\n\t\t\t}\n\treturn null;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://ideone.com/OpJmjY", | |
"DocumentationURL": "", | |
"AuthorComment": "A Java method returns 0 or 1 value only. So we have to create a custom class _Position to hold the two values to return.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 261, | |
"OrigId": 261, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "function search(m, x) {\n for (var i = 0; i \u003c m.length; i++) {\n for (var j = 0; j \u003c m[i].length; j++) {\n if (m[i][j] == x) {\n return [i, j];\n }\n }\n }\n return false;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://jsfiddle.net/vzw4577n/", | |
"DocumentationURL": "", | |
"AuthorComment": "Return an array if found, or _false if not found.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 315, | |
"OrigId": 315, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub search {\n my ($x, $m) = @_;\n while ( ($k1,$v1) = each @$m ) {\n while ( ($k2, $v2) = each @$v1 ) {\n return $k1, $k2 if $v2 == $x;\n }\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 453, | |
"OrigId": 453, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "Sh4rK", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn search\u003cT: Eq\u003e(m: \u0026Vec\u003cVec\u003cT\u003e\u003e, x: \u0026T) -\u003e Option\u003c(usize, usize)\u003e {\n for (i, row) in m.iter().enumerate() {\n for (j, column) in row.iter().enumerate() {\n if *column == *x {\n return Some((i, j));\n }\n }\n }\n\n None\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/LfOw8P", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T15:33:13.422795Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 482, | |
"OrigId": 482, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "void search(void ***m,void *x,size_t memb_size,int len_x,int len_y,int *i,int *j)\n{\n\tfor(*i=0;*i\u003clen_x;*i+=1)\n\t{\n\t\tfor(*j=0;*j\u003clen_y;*j+=1)\n\t\t{\n\t\t\tif(!memcmp(m[*i][*j],x,memb_size))\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t*i=*j=-1;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_m is a matrix containing type (void *) pointing to the data (can be anything)\r\n\r\n_x is the pointer to the data to look for\r\n\r\n_memb_size is the size of one element in bytes (to be able to compare anything)\r\n\r\n_len_x and _len_y are the dimensions\r\n\r\n_i and _j are passed by reference and contain the values, or -1 if _x was not found, after the function returned.", | |
"Version": 2, | |
"VersionDate": "2017-12-28T22:35:23.11483Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 536, | |
"OrigId": 536, | |
"Author": "jwhear", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "jwhear", | |
"LanguageName": "D", | |
"CodeBlock": "auto search(int[][] m, int x)\n{\n\tforeach (i, row; m)\n\t{\n\t\tforeach (j, cell; row)\n\t\t{\n\t\t\tif (cell == x)\n\t\t\t\treturn tuple(i, j);\n\t\t}\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.typecons;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 573, | |
"OrigId": 573, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "Python", | |
"CodeBlock": "def search(m, x):\n for idx, item in enumerate(m):\n if x in item:\n return idx, item.index(x)", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/5775397/923933", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 633, | |
"OrigId": 633, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "class Position {\n int i, j;\n Position(this.i, this.j);\n}\nPosition search(List\u003cList\u003e m, x) {\n for (var i = 0; i \u003c m.length; i++) {\n var line = m[i];\n for (var j = 0; j \u003c line.length; j++) {\n if (line[j] == x) {\n return new Position(i, j);\n }\n }\n }\n return null;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 646, | |
"OrigId": 646, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "procedure search(m:T2dMatrix; x:TElement; out i,j:integer);\nbegin\n for i := 0 to high(m) do\n\tfor j := 0 to high(m[i]) do\n if m[i,j] = x then\n exit;\n i := -1;\n j := -1;\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.87247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 893, | |
"OrigId": 893, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def search(m, x)\n m.each_with_index do |row, i|\n row.each_with_index do |value, j|\n return i, j if value == x\n end\n end\n nil\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-06-17T22:37:52.184514Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 956, | |
"OrigId": 956, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:26.87247Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "search x m = head [ (i, j) | (i, r) \u003c- zip [0..] m,\r\n (j, c) \u003c- zip [0..] r, c == x]\r\n\r\n\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Idiomatic list comprehension desugaring (head . findIndices (elem x) \u0026\u0026\u0026 head . head . filter (/=[]) . map (elemIndices x)) m", | |
"Version": 2, | |
"VersionDate": "2016-10-28T07:50:54.415368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1525, | |
"OrigId": 1525, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T20:37:05.65906Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "type Matrix is array (Positive range \u003c\u003e, Positive range \u003c\u003e) of Integer;\r\n\r\nfunction Search (M : Matrix; X : Integer; I, J : out Integer) return Boolean is\r\nbegin\r\n for K in M'Range (1) loop\r\n for L in M'Range (2) loop\r\n if M (K, L) = X then\r\n I := K;\r\n J := L;\r\n return True;\r\n end if; \r\n end loop;\r\n end loop;\r\n\r\n return False;\r\nend Search;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T20:37:05.65906Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1557, | |
"OrigId": 1557, | |
"Author": "Marti_2203", | |
"CreationDate": "2016-02-20T18:27:18.508587Z", | |
"LastEditor": "reifnir", | |
"LanguageName": "Csharp", | |
"CodeBlock": "(int, int) Search(int[,] m, int x)\n{\n for (var i = 0; i \u003c= m.GetUpperBound(0); i++)\n for (var j = 0; j \u003c= m.GetUpperBound(1); j++)\n if (m[i, j] == x)\n return (i, j);\n\n return (-1, -1);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7", | |
"AuthorComment": "In C# 7.0 and higher, you can return implicit tuples", | |
"Version": 5, | |
"VersionDate": "2019-09-26T15:22:58.866843Z", | |
"Rating": -2, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1576, | |
"OrigId": 1576, | |
"Author": "agilla1", | |
"CreationDate": "2016-02-24T15:45:31.141942Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function search($x, array $m): ?array\n{\n for ($j = 0; $j \u003c count($m); $j++) {\n if (($i = array_search($x, $m[$j])) !== false) {\n return [$i, $j];\n }\n }\n\n return null;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/function.array-search.php", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T08:58:32.11895Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1626, | |
"OrigId": 1626, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-04-05T04:13:29.48668Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-spec search(T, [[T]]) -\u003e {pos_integer(), pos_integer()}.\r\nsearch(X, M) -\u003e search(X, M, 1).\r\n\r\nsearch(_, [], _) -\u003e throw(notfound);\r\nsearch(X, [R|Rs], RN) -\u003e\r\n case search_row(X, R) of\r\n notfound -\u003e search(X, Rs, RN+1);\r\n CN -\u003e {RN, CN}\r\n end.\r\n\r\nsearch_row(X, Row) -\u003e search_row(X, Row, 1).\r\n\r\nsearch_row(_, [], _) -\u003e notfound;\r\nsearch_row(X, [X|_], CN) -\u003e CN;\r\nsearch_row(X, [_|Elems], CN) -\u003e search_row(X, Elems, CN+1).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=7ef3", | |
"DocumentationURL": "", | |
"AuthorComment": "_M is represented as a list of rows. Not using any function from the _lists module this time.", | |
"Version": 1, | |
"VersionDate": "2016-04-05T04:13:29.48668Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1661, | |
"OrigId": 1661, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T07:24:10.620219Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "function search(m, x)\r\n for i,v1 in ipairs(m) do\r\n for j,v2 in ipairs(v1) do\r\n if v2 == x then return i,j end\r\n end\r\n end\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/ZsNi8Ej5", | |
"DocumentationURL": "http://www.lua.org/pil/5.1.html", | |
"AuthorComment": "Lua functions may return multiple results", | |
"Version": 1, | |
"VersionDate": "2016-04-07T07:24:10.620219Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2101, | |
"OrigId": 2101, | |
"Author": "Jerry", | |
"CreationDate": "2017-09-01T15:46:17.789135Z", | |
"LastEditor": "jasonrobot", | |
"LanguageName": "Clojure", | |
"CodeBlock": " (defn find-in-2d-matrix [m x]\n (for [i (range (count m))\n j (range (count (first m)))\n :when (= x (-\u003e m (nth i) (nth j)))]\n [i j]))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T21:34:46.368442Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2594, | |
"OrigId": 2594, | |
"Author": "Debaran", | |
"CreationDate": "2019-02-02T03:06:18.399965Z", | |
"LastEditor": "Debaran", | |
"LanguageName": "Scala", | |
"CodeBlock": "def search[T](m: Iterable[Iterable[T]], x: T): Option[(Int, Int)] = {\n for ((row, i) \u003c- m.view.zipWithIndex; (column, j) \u003c- row.view.zipWithIndex if column == x)\n return Some((i, j))\n None\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_Note: This will refuse to work on _Array", | |
"Version": 1, | |
"VersionDate": "2019-02-02T03:06:18.399965Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2827, | |
"OrigId": 2827, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:45:57.577381Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defun mysearch (x m)\n (loop for i below (array-dimension m 0)\n do (loop for j below (array-dimension m 1)\n when (eql x (aref m i j))\n do (return-from my-search\n (values i j)))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:45:57.577381Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2839, | |
"OrigId": 2839, | |
"Author": "archi", | |
"CreationDate": "2019-09-26T15:56:08.551191Z", | |
"LastEditor": "archi", | |
"LanguageName": "Cpp", | |
"CodeBlock": "template\u003ctypename T, size_t len_x, size_t len_y\u003e\nstd::pair\u003csize_t, size_t\u003e search (const T (\u0026m)[len_x][len_y], const T \u0026x) {\n for(size_t pos_x = 0; pos_x \u003c len_x; ++pos_x) {\n for(size_t pos_y = 0; pos_y \u003c len_y; ++pos_y) {\n if(m[pos_x][pos_y] == x) {\n return std::pair\u003csize_t, size_t\u003e(pos_x, pos_y);\n }\n }\n }\n\n // return an invalid value if not found\n return std::pair\u003csize_t, size_t\u003e(len_x, len_y);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/repls/SereneWearyApplet", | |
"DocumentationURL": "", | |
"AuthorComment": "This tries to be similar to the C variant. In a real world program the 2D matrix should offer an iterator.\r\n\r\nThe elements can be accessed via _returnValue.first and _returnValue.second.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:56:49.484581Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cutility\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2919, | |
"OrigId": 2919, | |
"Author": "andrepd", | |
"CreationDate": "2019-09-26T17:02:27.869485Z", | |
"LastEditor": "andrepd", | |
"LanguageName": "Caml", | |
"CodeBlock": "module Arr = Bigarray.Array2\n\nlet search array value =\n\tlet x_max = Arr.dim1 array in\n\tlet y_max = Arr.dim2 array in\n\tlet rec loop x y = \n\t\t(* End of array *)\n\t\tif x = x_max then\n\t\t\traise Not_found\n\t\t(* End of row, go to next *)\n\t\telse if y = y_max then\n\t\t\tloop (x+1) 0\n\t\telse \n\t\t\t(* If found, return it *)\n\t\t\tif array.{x,y} = value then\n\t\t\t\t(x,y)\n\t\t\t(* Otherwise go to next col *)\n\t\t\telse\n\t\t\t\tloop x (y+1)\n\tin\n\tloop 0 0\n\n\n\n\n\n\t\t", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T17:04:41.611249Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3040, | |
"OrigId": 3040, | |
"Author": "jdashg", | |
"CreationDate": "2019-09-26T19:40:02.354833Z", | |
"LastEditor": "jdashg", | |
"LanguageName": "Cpp", | |
"CodeBlock": "bool _search(const Matrix\u0026 _m, const float _x, size_t* const out_i, size_t* const out_j) {\n for (size_t j = 0; j \u003c _m.rows; j++) {\n for (size_t i = 0; i \u003c _m.cols; i++) {\n if (_m.at(i, j) == _x) {\n *out_i = i;\n *out_j = j;\n return true;\n }\n }\n }\n return false;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:40:02.354833Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3075, | |
"OrigId": 3075, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:20:35.012999Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "function search(m,x)\n integer, dimension(:,:), intent(in) :: m\n integer, intent(in) :: x\n integer, dimension(2) :: search\n search = findloc(x,m)\nend function search", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This duplicates the functionality of FINDLOC in Fortran, so I am using this.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:20:35.012999Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 24, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
126 | |
], | |
"RelatedIdiomTitles": [ | |
"Multiple return values" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 21, | |
"OrigId": 0, | |
"Title": "Swap values of variables a and b", | |
"LeadParagraph": "", | |
"ExtraKeywords": "exchange", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [spectrum]", | |
"LastEditedImplID": 3460, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 31, | |
"VersionDate": "2019-09-28T19:59:36.803528Z", | |
"Implementations": [ | |
{ | |
"Id": 84, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "a, b = b, a", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 85, | |
"OrigId": 85, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "a, b = b, a", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/If58vpyJbO", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 86, | |
"OrigId": 86, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var tmp = a;\na = b;\nb = tmp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 87, | |
"OrigId": 87, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "T tmp = a;\na = b;\nb = tmp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This assumes _a and _b are of type _T.\r\n_T may be a class or a primitive type.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 88, | |
"OrigId": 88, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "$tmp = $a;\n$a = $b;\n$b = $tmp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Using a third variable is the only way to keep performance good.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 92, | |
"OrigId": 92, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "nv", | |
"LanguageName": "Ruby", | |
"CodeBlock": "a, b = b, a", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 299, | |
"OrigId": 299, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "($a, $b) = ($b, $a);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Simple, no?", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 399, | |
"OrigId": 399, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "carlomilanesi", | |
"LanguageName": "Rust", | |
"CodeBlock": "std::mem::swap(\u0026mut a, \u0026mut b);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/ffJcKU", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-05-26T05:52:11.365132Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 472, | |
"OrigId": 472, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "C", | |
"CodeBlock": "a^=b;\nb^=a;\na^=b;\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Only works for integer values (or casted pointers)", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 535, | |
"OrigId": 535, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "auto temp = a;\na = b;\nb = temp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 610, | |
"OrigId": 610, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "var tmp = a;\na = b;\nb = tmp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 645, | |
"OrigId": 645, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "tmp := a;\r\na := b;\r\nb := tmp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_tmp needs to be a variable of type of _a and _b.", | |
"Version": 2, | |
"VersionDate": "2017-04-12T16:09:10.428865Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 829, | |
"OrigId": 829, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "swap (a,b) = (b,a)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 938, | |
"OrigId": 938, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:26.93472Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "{a, b} = {b, a}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/69f0b84cbd", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:26.93472Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1127, | |
"OrigId": 1127, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T03:05:34.991096Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "fun1(A, B) -\u003e\r\n\tdo:something(),\r\n\tfun2(B, A).\r\n\r\nfun2(A, B) -\u003e\r\n\tnow(A, is, B),\r\n\tand(B, is, A),\r\n\tkeep:moving().", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://stackoverflow.com/questions/9753080/is-erlang-single-assignment-different-from-haskell-immutable-values", | |
"AuthorComment": "Single assignment precludes you from _swapping values in Erlang within the body of a single function.\r\nIf you _really want the names to change (which you usually _don't)… well… you have to move to a different function", | |
"Version": 1, | |
"VersionDate": "2015-12-18T03:05:34.991096Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1339, | |
"OrigId": 1339, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T16:59:39.386856Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "a, b = b, a", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:59:39.386856Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1375, | |
"OrigId": 1375, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T18:25:47.464523Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "swap(a, b);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/algorithm/swap", | |
"AuthorComment": "This is the most proper way. There are plenty of other ways, but this one should be the most correct, generic and performant.", | |
"Version": 1, | |
"VersionDate": "2016-02-16T18:25:47.464523Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cutility\u003e\r\nusing std::swap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1447, | |
"OrigId": 1447, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:55:20.610334Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "var a = 1\r\nvar b = 2\r\nval tmp = a\r\na = b\r\nb = tmp\r\n\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:55:20.610334Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1496, | |
"OrigId": 1496, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:07:33.991504Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "var tmp = a;\r\na = b;\r\nb = tmp;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-02-17T13:18:31.409193Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1871, | |
"OrigId": 1871, | |
"Author": " ", | |
"CreationDate": "2016-10-29T02:12:10.139381Z", | |
"LastEditor": " ", | |
"LanguageName": "JS", | |
"CodeBlock": "[a, b] = [b, a];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Swapping_variables", | |
"AuthorComment": "ECMA2015 and above", | |
"Version": 1, | |
"VersionDate": "2016-10-29T02:12:10.139381Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2067, | |
"OrigId": 2067, | |
"Author": "Doeme", | |
"CreationDate": "2017-07-29T12:22:04.120285Z", | |
"LastEditor": "Doeme", | |
"LanguageName": "D", | |
"CodeBlock": "swap(a,b);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://dlang.org/phobos/std_algorithm_mutation.html#.swap", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-07-29T12:22:04.120285Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm.mutation : swap;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2863, | |
"OrigId": 2863, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:20:47.679506Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(rotatef a b)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:20:47.679506Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3122, | |
"OrigId": 3122, | |
"Author": "no_sol", | |
"CreationDate": "2019-09-26T21:58:18.393052Z", | |
"LastEditor": "no_sol", | |
"LanguageName": "Csharp", | |
"CodeBlock": "(a, b) = (b, a);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dotnetfiddle.net/bB9Y3G", | |
"DocumentationURL": "https://docs.microsoft.com/en-us/dotnet/csharp/tuples#deconstruction", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:58:18.393052Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3322, | |
"OrigId": 3322, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-27T21:25:07.65016Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. swap.\nPROCEDURE DIVISION.\n MOVE a TO temp\n MOVE b TO a\n MOVE temp TO b\nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T21:39:48.554171Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3460, | |
"OrigId": 3460, | |
"Author": "spectrum", | |
"CreationDate": "2019-09-28T19:59:36.800062Z", | |
"LastEditor": "spectrum", | |
"LanguageName": "Fortran", | |
"CodeBlock": "tmp = a\na = b\nb = tmp", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_tmp needs to be a variable of type _a and _b. This also works when _a, _b, and _tmp are multidimensional arrays.", | |
"Version": 1, | |
"VersionDate": "2019-09-28T19:59:36.800062Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 25, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
10 | |
], | |
"RelatedIdiomTitles": [ | |
"Shuffle a list" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 22, | |
"OrigId": 0, | |
"Title": "Convert string to integer", | |
"LeadParagraph": "Extract integer value _i from its string representation _s (in radix 10)", | |
"ExtraKeywords": "int base conversion", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New VB implementation by user [EvilGenius]", | |
"LastEditedImplID": 3366, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/22/string-to-int.png", | |
"Version": 75, | |
"VersionDate": "2019-09-27T23:21:04.613916Z", | |
"Implementations": [ | |
{ | |
"Id": 105, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "int i = Integer.parseInt(s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This will throw NumberFormatException if _s does not contain a parsable integer", | |
"Version": 2, | |
"VersionDate": "2016-11-27T14:44:09.987408Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 106, | |
"OrigId": 106, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "int i = new Integer(s).intValue();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#Integer%28java.lang.String%29", | |
"AuthorComment": "This will throw NumberFormatException if _s does not contain a parsable integer", | |
"Version": 2, | |
"VersionDate": "2016-11-27T14:43:55.881322Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 119, | |
"OrigId": 119, | |
"Author": "nv", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "i = s.to_i", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWrW/0", | |
"DocumentationURL": "http://ruby-doc.org/core-2.3.0/String.html#to_i-method", | |
"AuthorComment": "_to_i returns 0 if _s is not a valid number.", | |
"Version": 2, | |
"VersionDate": "2016-11-13T22:34:44.207442Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 167, | |
"OrigId": 167, | |
"Author": "Henri Lepic", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "i, err := strconv.Atoi(s) ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/YjYPEj10ms", | |
"DocumentationURL": "http://golang.org/pkg/strconv/#Atoi", | |
"AuthorComment": "_Atoi(_s) is shorthand for _ParseInt(_s, 10, 0). It yields type _int.", | |
"Version": 2, | |
"VersionDate": "2016-11-13T22:37:04.698218Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"strconv\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 172, | |
"OrigId": 172, | |
"Author": "sylvain", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "dacap", | |
"LanguageName": "Cpp", | |
"CodeBlock": "int i = std::atoi(s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/string/byte/atoi", | |
"AuthorComment": "_s is a char*", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ccstdlib\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 203, | |
"OrigId": 203, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var i = int.parse(s);", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/13167498/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 238, | |
"OrigId": 238, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "i, err := strconv.ParseInt(s, 10, 0)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/YkNeMgbLYe", | |
"DocumentationURL": "http://golang.org/pkg/strconv/#ParseInt", | |
"AuthorComment": "Radix 10. Third argument _0 means \"fit in implementation-specific _int\". But result type is always _int64.\r\nDon't ignore the potential error _err !", | |
"Version": 2, | |
"VersionDate": "2016-11-13T22:40:13.355738Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"strconv\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 243, | |
"OrigId": 243, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "i = int(s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 247, | |
"OrigId": 247, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "i = Convert.ToInt64(s);", | |
"OriginalAttributionURL": "http://msdn.microsoft.com/en-us/library/bb397679.aspx", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "May throw _FormatException and _OverflowException.\r\n_ToInt32 also exists.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 294, | |
"OrigId": 294, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $i = $s + 0;\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Perl automatically converts numbers to strings, and strings to numbers, whenever required.\r\n\r\n+ is addition, not concatenation.", | |
"Version": 3, | |
"VersionDate": "2016-10-20T11:43:09.174437Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 404, | |
"OrigId": 404, | |
"Author": "kstep", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let i = s.parse::\u003ci32\u003e().unwrap();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This panics if _s is not a valid number.\r\n_s is parsed to 32-bits signed integer here (change number type if needed).\r\n", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 425, | |
"OrigId": 425, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "$i = intval($s, 10);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 468, | |
"OrigId": 468, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "C", | |
"CodeBlock": "int i=atoi(s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 517, | |
"OrigId": 517, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "auto i = s.to!int;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The useful _to function can convert just about anything to something else. It will throw on a non-integral input string.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.conv;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 544, | |
"OrigId": 544, | |
"Author": "killercup", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let i: i32 = s.parse().unwrap_or(0);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20s%20%3D%20%2242%22%3B%0A%20%20%20%20let%20i%3A%20i32%20%3D%20s.parse().unwrap_or(0)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%7D%22%2C%20i)%3B%0A%7D%0A\u0026version=stable", | |
"DocumentationURL": "", | |
"AuthorComment": "This explicitly sets the value to _0 if it can't be parsed to an integer.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 590, | |
"OrigId": 590, | |
"Author": "Bart", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "i := StrToInt(S);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The function _StrToInt will raise an exception of type EConvertError if the string is not a proper representation of an integer.", | |
"Version": 2, | |
"VersionDate": "2016-11-27T14:47:52.290217Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses SysUtils;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 802, | |
"OrigId": 802, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "let i = read s :: Integer", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-27T14:41:52.936516Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 808, | |
"OrigId": 808, | |
"Author": "jfacorro", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(Integer/parseInt s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 921, | |
"OrigId": 921, | |
"Author": "ventsislaf", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "i = String.to_integer(s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/3af6da9d91", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/String.html#to_integer/1", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T20:49:25.486209Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1062, | |
"OrigId": 1062, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "I = list_to_integer(S).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/current/erts/erlang.html?i=0\u0026search=list_to_inte#list_to_integer/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1163, | |
"OrigId": 1163, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let i = match s.parse::\u003ci32\u003e() {\n Ok(i) =\u003e i,\n Err(e) =\u003e {\n -1\n }\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_s is parsed to 32-bits signed integer here (change number type if needed).\r\n-_1 is used here as a fallback value, but any error handling instructions can be used.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1301, | |
"OrigId": 1301, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "i = tonumber(s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1310, | |
"OrigId": 1310, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "I := Integer'Value (s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.820172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1433, | |
"OrigId": 1433, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:57.820172Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scala", | |
"CodeBlock": "s.toInt", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-27T14:50:16.682879Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1958, | |
"OrigId": 1958, | |
"Author": "otonashinotachi", | |
"CreationDate": "2017-04-05T10:44:11.310803Z", | |
"LastEditor": "otonashinotachi", | |
"LanguageName": "JS", | |
"CodeBlock": "i = parseInt(\"23\", 10)", | |
"OriginalAttributionURL": "https://www.w3schools.com/jsref/jsref_parseint.asp", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/parseInt", | |
"AuthorComment": "parseInt(string, radix);\r\nRadix is an integer between 2 and 36 that represents the radix of the above mentioned string.", | |
"Version": 1, | |
"VersionDate": "2017-04-05T10:44:11.310803Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2012, | |
"OrigId": 2012, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-06T15:19:09.918667Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define i (string-\u003enumber s))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-06T15:19:09.918667Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2199, | |
"OrigId": 2199, | |
"Author": "Jeff", | |
"CreationDate": "2017-12-27T11:55:52.693665Z", | |
"LastEditor": "Jeff", | |
"LanguageName": "Cpp", | |
"CodeBlock": "int i = std::stoi(s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://coliru.stacked-crooked.com/a/3630bd8b3b6fbad1", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/string/basic_string/stol", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-12-27T11:55:52.693665Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2666, | |
"OrigId": 2666, | |
"Author": "tormenta77", | |
"CreationDate": "2019-07-05T18:02:43.057509Z", | |
"LastEditor": "tormenta77", | |
"LanguageName": "Rust", | |
"CodeBlock": "let num : i32 = line.trim().parse()\n .expect(msg: \u0026str);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-07-05T18:02:43.057509Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2849, | |
"OrigId": 2849, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:03:16.1024Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(setf i (parse-integer s))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:03:16.1024Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2908, | |
"OrigId": 2908, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:57:07.589213Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "read (unit=s,fmt=*) i", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:57:07.589213Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2985, | |
"OrigId": 2985, | |
"Author": "jay", | |
"CreationDate": "2019-09-26T17:53:12.431896Z", | |
"LastEditor": "jay", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "s.toInt()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:53:12.431896Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2988, | |
"OrigId": 2988, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T17:54:30.677767Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val i = s.toInt()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:54:30.677767Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3103, | |
"OrigId": 3103, | |
"Author": "gumbo59", | |
"CreationDate": "2019-09-26T21:29:08.690734Z", | |
"LastEditor": "gumbo59", | |
"LanguageName": "JS", | |
"CodeBlock": "const i = Number(s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:29:08.690734Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3126, | |
"OrigId": 3126, | |
"Author": "Blooser", | |
"CreationDate": "2019-09-26T22:06:28.351336Z", | |
"LastEditor": "Blooser", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::stringstream ss(str);\nint i;\nss \u003e\u003e i;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:06:28.351336Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring\u003e\r\n#include \u003csstream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3366, | |
"OrigId": 3366, | |
"Author": "EvilGenius", | |
"CreationDate": "2019-09-27T23:21:04.609373Z", | |
"LastEditor": "EvilGenius", | |
"LanguageName": "VB", | |
"CodeBlock": "Dim myint As Integer = CInt((\"123\"))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:21:04.609373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 35, | |
"Rating": 1, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
55, | |
146 | |
], | |
"RelatedIdiomTitles": [ | |
"Convert integer to string", | |
"Convert string to floating point number" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 23, | |
"OrigId": 0, | |
"Title": "Convert real number to string with 2 decimal places", | |
"LeadParagraph": "Given real number _x, create its string representation _s with 2 decimal digits following the dot.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[PHP] Format code snippet to PSR-12, use single quotes for higher performance", | |
"LastEditedImplID": 464, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 27, | |
"VersionDate": "2019-09-27T09:50:30.589693Z", | |
"Implementations": [ | |
{ | |
"Id": 107, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "s := fmt.Sprintf(\"%.2f\", x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/ljo0tAbT_t", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"fmt\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 340, | |
"OrigId": 340, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "$s = sprintf \"%.2f\", $x;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 464, | |
"OrigId": 464, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "$s = sprintf('%.2f', $x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T09:50:30.587171Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 467, | |
"OrigId": 467, | |
"Author": "killercup", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let s = format!(\"{:.2}\", x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%2042.1337%3B%0A%20%20%20%20let%20s%20%3D%20format!(%22%7B%3A.2%7D%22%2C%20x)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%7D%22%2C%20s)%3B%0A%7D%0A\u0026version=stable", | |
"DocumentationURL": "http://doc.rust-lang.org/std/fmt/index.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 533, | |
"OrigId": 533, | |
"Author": "wobbles", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "schuetzm", | |
"LanguageName": "D", | |
"CodeBlock": "string str = format(\"%.2s\", x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.string;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 648, | |
"OrigId": 648, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "s := format('%.2f',[ x]);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "SysUtils", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 728, | |
"OrigId": 728, | |
"Author": "LRHN", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "var s = x.toStringAsFixed(2);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:core.num#id_toStringAsFixed", | |
"AuthorComment": "Only works up to 1e+21, then it uses exponential notation.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 873, | |
"OrigId": 873, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "s = \"%.2f\" % x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 918, | |
"OrigId": 918, | |
"Author": "ventsislaf", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "s = Float.to_string(x, decimals: 2)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/916870f5f8", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/Float.html#to_string/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 966, | |
"OrigId": 966, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "s \u003c- showFFloat (Just 2) x \"\"\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1102, | |
"OrigId": 1102, | |
"Author": "nickname", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "nickname", | |
"LanguageName": "Python", | |
"CodeBlock": "s = '{:.2f}'.format(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/3/library/stdtypes.html#str.format", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1461, | |
"OrigId": 1461, | |
"Author": "lbayer", | |
"CreationDate": "2016-02-18T16:57:57.897385Z", | |
"LastEditor": "lbayer", | |
"LanguageName": "Java", | |
"CodeBlock": "String s = String.format(\"%.2f\", x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:57.897385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1687, | |
"OrigId": 1687, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-08T13:21:49.307022Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "s = string.format(\"%.2f\",x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/bcj9cyZR", | |
"DocumentationURL": "http://www.lua.org/manual/5.3/manual.html#pdf-string.format", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-08T13:21:49.307022Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1754, | |
"OrigId": 1754, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-07-12T21:12:02.302274Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "S = io_lib:format(\"~.2f\", [X]).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_S will be an iolist(), technically not a string() but it's good enough for most purposes and you can always use _iolist_to_binary/1", | |
"Version": 1, | |
"VersionDate": "2016-07-12T21:12:02.302274Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1817, | |
"OrigId": 1817, | |
"Author": "DrSpoktopus", | |
"CreationDate": "2016-09-03T20:35:24.467902Z", | |
"LastEditor": "DrSpoktopus", | |
"LanguageName": "Csharp", | |
"CodeBlock": "string s = $\"{x:F2}\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-09-03T20:35:24.467902Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1998, | |
"OrigId": 1998, | |
"Author": "Dodopod", | |
"CreationDate": "2017-05-27T19:39:02.239565Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "C", | |
"CodeBlock": "sprintf(s, \"%.2f\", x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-05-27T19:39:02.239565Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdio.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2452, | |
"OrigId": 2452, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T14:04:07.390031Z", | |
"LastEditor": "chillitom", | |
"LanguageName": "JS", | |
"CodeBlock": "num.toFixed(2)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://codepen.io/chillitom/pen/pozBbWw?editors=1111", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T14:06:32.276868Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2916, | |
"OrigId": 2916, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T17:01:55.772767Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " write (unit=s,fmt=\"(F20.2)\") x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:01:55.772767Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 18, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 24, | |
"OrigId": 0, | |
"Title": "Assign to string the japanese word ネコ", | |
"LeadParagraph": "Declare a new string _s and initialize it with the literal value \"ネコ\" (which means \"cat\" in japanese)", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New C implementation by user [phrank]", | |
"LastEditedImplID": 3409, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 31, | |
"VersionDate": "2019-09-28T07:44:05.095008Z", | |
"Implementations": [ | |
{ | |
"Id": 108, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "s := \"ネコ\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/6u1heQRlj2", | |
"DocumentationURL": "https://blog.golang.org/strings", | |
"AuthorComment": "UTF-8 literals are valid in Go.\r\n\r\nAlso the source code in Go is defined to be UTF-8 text; No other representation is allowed.", | |
"Version": 2, | |
"VersionDate": "2015-12-28T16:02:35.02546Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 217, | |
"OrigId": 217, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "String s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/c6xO1v", | |
"DocumentationURL": "", | |
"AuthorComment": "Literal strings with UTF-16 characters are legal in Java. Just be careful with your source file encoding, or use escaping.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 323, | |
"OrigId": 323, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "Tom Legrady", | |
"LanguageName": "Perl", | |
"CodeBlock": "$s = 'ネコ';", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The _utf8 module tells perl that the source code is in unicode.", | |
"Version": 2, | |
"VersionDate": "2016-02-16T16:15:57.588283Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use utf8;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 373, | |
"OrigId": 373, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "JavaScript was designed to use unicode.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 422, | |
"OrigId": 422, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "$s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 447, | |
"OrigId": 447, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "let s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/txe3II", | |
"DocumentationURL": "", | |
"AuthorComment": "Make sure to always save your source code files as UTF-8.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 542, | |
"OrigId": 542, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "string s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 642, | |
"OrigId": 642, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "var s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/aeea9f78b24301baef3c", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 664, | |
"OrigId": 664, | |
"Author": "cym13", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "cym13", | |
"LanguageName": "Python", | |
"CodeBlock": "s = \"ネコ\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 814, | |
"OrigId": 814, | |
"Author": "jfacorro", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "jfacorro", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(def s \"ネコ\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://clojuredocs.org/clojure.core/def", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 845, | |
"OrigId": 845, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "s = \"ネコ\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWdN/0", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-13T14:55:33.585884Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 927, | |
"OrigId": 927, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "s = \"ネコ\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/e74bbda617", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/String.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 950, | |
"OrigId": 950, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.133314Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "s = \"ネコ\"\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.133314Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1132, | |
"OrigId": 1132, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T03:17:18.99215Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "S = unicode:characters_to_binary(\"ネコ\"),", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=05f3", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-12-18T03:17:18.99215Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1228, | |
"OrigId": 1228, | |
"Author": "Bart", | |
"CreationDate": "2016-01-15T15:11:37.575155Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "{$codepage utf8}\r\ns := \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "{$codepage utf8}: Explain to the compiler the file (and therefore a string literal) is UTF8 encoded.\r\nYou can assign UTF8 literals.", | |
"Version": 2, | |
"VersionDate": "2016-01-21T09:19:05.87042Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1340, | |
"OrigId": 1340, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T17:00:41.436241Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "s = 'ネコ'", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:00:41.436241Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1373, | |
"OrigId": 1373, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T18:22:59.730897Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::string s = u8\"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This creates a UTF-8 string object. You can use other string types (wide string, UTF-16, UTF-32) by using different types and literal prefixes.", | |
"Version": 1, | |
"VersionDate": "2016-02-16T18:22:59.730897Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1448, | |
"OrigId": 1448, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:56:08.214941Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val s = \"ネコ\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:56:08.214941Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1497, | |
"OrigId": 1497, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:08:53.881874Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "string s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:08:53.881874Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2950, | |
"OrigId": 2950, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T17:26:28.977878Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " use, intrinsic :: iso_fortran_env\n implicit none\n integer, parameter :: u = selected_char_kind('ISO_10646')\n\n character(kind=u,len=2) :: cat\n cat = u_\"ネコ\"\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:26:28.977878Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3409, | |
"OrigId": 3409, | |
"Author": "phrank", | |
"CreationDate": "2019-09-28T07:44:05.087104Z", | |
"LastEditor": "phrank", | |
"LanguageName": "C", | |
"CodeBlock": "const char * s = \"ネコ\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "C has no notion of character sets, output depends on locale settings and terminal capabilities.", | |
"Version": 1, | |
"VersionDate": "2019-09-28T07:44:05.087104Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 21, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 25, | |
"OrigId": 0, | |
"Title": "Send a value to another thread", | |
"LeadParagraph": "Share the string value \"Alan\" with an existing running process which will then display \"Hello, Alan\"", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [tkoenig]", | |
"LastEditedImplID": 3448, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 26, | |
"VersionDate": "2019-09-28T16:09:23.818735Z", | |
"Implementations": [ | |
{ | |
"Id": 109, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "ch \u003c- \"Alan\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/WFCwUKkPp9", | |
"DocumentationURL": "", | |
"AuthorComment": "The receiver goroutine blocks reading the string channel _ch.\r\nThe current goroutine sends the value to _ch.\r\nA _goroutine is like a thread, but more lightweight.", | |
"Version": 2, | |
"VersionDate": "2016-11-04T16:37:35.780952Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 195, | |
"OrigId": 195, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "q = Queue()\n\nt = Thread(target=worker)\nt.daemon = True\nt.start()\n\nq.put(\"Alan\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/2/library/queue.html", | |
"AuthorComment": "The _Queue module has been renamed to _queue in Python 3.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Queue", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 352, | |
"OrigId": 352, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my @queue :shared;\n\nthreads-\u003ecreate('my_task');\npush @queue, 'Alan';\nsleep 5;\n\nsub my_task {\n while (1) {\n while (@queue) {\n print \"Hello, \", (pop @queue), \"\\n\";\n }\n sleep 1;\n}\n\n \n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "We sleep so that the thread can print the greeting before the program ends.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use threads;\r\nuse threads::shared;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 423, | |
"OrigId": 423, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "Rust", | |
"CodeBlock": "let (send,recv)=channel();\n\nthread::spawn(move||\n{ \n loop\n { \n let msg=recv.recv().unwrap();\n println!(\"Hello, {:?}\",msg);\n } \n});\n\nsend.send(\"Alan\").unwrap();\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The message might not be printed if the main thread exits before the thread has written to stdout.\r\n", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::thread;\r\nuse std::sync::mpsc::channel;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 457, | |
"OrigId": 457, | |
"Author": "Flyingmana", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "class AsyncOperation extends Thread\n{\n private $name;\n\n public function __construct($arg)\n {\n $this-\u003ename = $arg;\n }\n\n public function run()\n {\n sleep(1);\n if ($this-\u003ename) {\n printf(\"Hello %s\\n\", $this-\u003ename);\n }\n }\n}\n\n$thread = new AsyncOperation(\"World\");\n\nif ($thread-\u003estart()) {\n $thread-\u003emerge(['name' =\u003e 'Alan']);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T10:19:44.788417Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extension=pthreads.so\r\n", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 458, | |
"OrigId": 458, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "Java", | |
"CodeBlock": "https://gist.github.com/f7c174c53efaba4d8575", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://goo.gl/5bJ3i7", | |
"DocumentationURL": "", | |
"AuthorComment": "I tried to put in in here, but it was just too long.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 565, | |
"OrigId": 565, | |
"Author": "schveiguy", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "auto t = spawn( {\r\n receive( (string s) { writefln(\"Hello, %s\", s); } );\r\n} );\r\n\r\nt.send(\"Alan\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_receive takes as parameters lambda functions (or delegates) to handle each type that may be received.", | |
"Version": 2, | |
"VersionDate": "2016-11-07T12:40:44.550442Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.concurrency;\r\nimport std.stdio;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 758, | |
"OrigId": 758, | |
"Author": "Geep Jeez", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "Geep Jeez", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var Queue: TIdThreadSafeStringList;\n\ntype\n\nTTask = class(TThread)\n procedure Execute; override;\nend;\n\nprocedure TTask.Execute;\nbegin\n while not Terminated do begin\n Sleep(10);\n with Queue.Lock do try\n while Count \u003e 0 do begin\n WriteLn('Hello, ', Strings[0]);\n Delete(0);\n end;\n finally\n Queue.Unlock;\n end;\n end;\nend;\n\nbegin\n Queue := TIdThreadSafeStringList.Create;\n TTask.Create(False);\n Queue.Add('Alan');\n Sleep(5000);\nend. \n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.e-iter.net/Knowledge/Indy9/007862.html", | |
"AuthorComment": "It looks like the other implementations use queues. Due to the space limitation, I used the TIdThreadSafeStringList class from Indy for a threadsafe message queue. For standard FP code, use TThreadList with your own TObject based message.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "Uses IdThreadSafe; // From Indy", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 972, | |
"OrigId": 972, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "writeChan peopleToGreet \"Alan\"\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Control-Concurrent-Chan.html#v:writeChan", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Control.Concurrent.Chan", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1047, | |
"OrigId": 1047, | |
"Author": "LRHN", | |
"CreationDate": "2016-02-18T16:57:58.135862Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "sendPort.send(\"value\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Ports are used for communicating between individually running isolates. The receiving isolate has created the corresponding receive-port and passed the send-port to this isolate.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.135862Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"dart:isolate\";", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2556, | |
"OrigId": 2556, | |
"Author": "1.7.4", | |
"CreationDate": "2019-01-24T12:01:46.551105Z", | |
"LastEditor": "1.7.4", | |
"LanguageName": "JS", | |
"CodeBlock": "{\n // in file worker.js\n onmessage = ({data}) =\u003e {\n console.log (`Hello, ${data}`)\n }\n}\n{\n // in file main.js\n const worker = new Worker ('worker.js')\n worker.postMessage ('Alan')\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Not supported in Internet Explorer or NodeJS.", | |
"Version": 2, | |
"VersionDate": "2019-01-24T12:02:55.106761Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3123, | |
"OrigId": 3123, | |
"Author": "pokoika", | |
"CreationDate": "2019-09-26T22:00:36.099904Z", | |
"LastEditor": "pokoika", | |
"LanguageName": "Ruby", | |
"CodeBlock": "queue = Queue.new\nthread = Thread.new do\n puts queue.pop\nend\nqueue \u003c\u003c \"Alan\"\nthread.join\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:00:36.099904Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3448, | |
"OrigId": 3448, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-28T16:09:23.814899Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "str[1] = \"Alan\"\nsync all\nif (this_image() == 1) then\n print *,\"Hello, \", str\nend if", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This uses the co-array features of Fortran.", | |
"Version": 1, | |
"VersionDate": "2019-09-28T16:09:23.814899Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 13, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 26, | |
"OrigId": 0, | |
"Title": "Create a 2-dimensional array", | |
"LeadParagraph": "Declare and initialize a matrix _x having _m rows and _n columns, containing real numbers.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Python] Emphasize xrange is a Python 2.7 function", | |
"LastEditedImplID": 194, | |
"OriginalAttributionURL": "", | |
"Picture": "AMIfv94e4k0ht7-O5xeSfYcmLbTf2iaBr8XUVHfo_YBXTv4vZWOQevYZ9R0-esSFPv3AJ9xN0JzHanML15zLAgQca5klZznCYHfWWVGzKgm-hHPSkY8x_GPZAUsMdY5Ae2HThsDFJ4bOeFul2SedJH6v9n32uoJvUzChSg308o6B_YTOwaSqFuU", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/26/2D-matrix.png", | |
"Version": 62, | |
"VersionDate": "2019-09-27T03:01:31.946797Z", | |
"Implementations": [ | |
{ | |
"Id": 110, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "double[][] x = new double[m][n];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/tWa2Nf", | |
"DocumentationURL": "", | |
"AuthorComment": "Initial values are 0.0\r\n_m and _n need not be known at compile time", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 146, | |
"OrigId": 146, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "const m, n = 3, 4\nvar x [m][n]float64", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/bm0IVTCBiu2", | |
"DocumentationURL": "", | |
"AuthorComment": "_m, _n must be constant for this syntax to be valid.\r\nHere _x is of type [3][4]float64, it is not a slice.", | |
"Version": 3, | |
"VersionDate": "2018-05-09T20:32:38.554113Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 194, | |
"OrigId": 194, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "sgdpk", | |
"LanguageName": "Python", | |
"CodeBlock": "x = [[0 for j in xrange(n)] for i in xrange(m)]", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/6667288/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Python 2.7", | |
"Version": 2, | |
"VersionDate": "2019-09-27T03:01:31.943197Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 263, | |
"OrigId": 263, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "fibre", | |
"LanguageName": "JS", | |
"CodeBlock": "var x = [];\nfor (var i = 0; i \u003c m; i++) {\n x[i] = [];\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/24407669/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:48:24.961601Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 306, | |
"OrigId": 306, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my @array = (\n [ 1.0, 0.0, 0.0 ],\n [ 0.0, 1.0, 0.0 ],\n [ 0.0, 0.0, 1.0 ],\n \"first three slots are a 3x3 identity matrix\",\n \"fourth and fifth slots contain strings\"\n);\n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Perl has only one-dimensional arrays, but since each slot may hold an array, you can make as many dimensions as you want.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 448, | |
"OrigId": 448, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "let x = vec![vec![0.0f64; N]; M];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/w2yN9Y", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 475, | |
"OrigId": 475, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "double **x=malloc(m*sizeof(double *));\r\nint i;\r\nfor(i=0;i\u003cm;i++)\r\n\tx[i]=malloc(n*sizeof(double));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This uses dynamic allocation.", | |
"Version": 3, | |
"VersionDate": "2016-11-04T11:53:50.934603Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 525, | |
"OrigId": 525, | |
"Author": "jwhear", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "jwhear", | |
"LanguageName": "D", | |
"CodeBlock": "auto x = new double[][](m, n);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The matrix elements will automatically be initialized to NaN.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 631, | |
"OrigId": 631, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "var x = new List.generate(m, (_) =\u003e new List(n));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/bbaedea5cd0d8d2cfdc8", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 687, | |
"OrigId": 687, | |
"Author": "Bart", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "Bart", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var _x: array[_m,_n] of Double;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_m and _n need to be constants of type Integer (and declared before the definition of variable _x)", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 859, | |
"OrigId": 859, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x = Array.new(m) { Array.new(n) }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/Array.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 957, | |
"OrigId": 957, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.532323Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "x = [ [ j**(1/i) | j \u003c- [1..n] ] | i \u003c- [1..m] ]\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.532323Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1161, | |
"OrigId": 1161, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-12-30T17:50:58.409059Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func make2D(m, n int) [][]float64 {\n\tbuf := make([]float64, m*n)\n\n\tx := make([][]float64, m)\n\tfor i := range x {\n\t\tx[i] = buf[:n:n]\n\t\tbuf = buf[n:]\n\t}\n\treturn x\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/hURXPWWziq", | |
"DocumentationURL": "https://golang.org/doc/effective_go.html#two_dimensional_slices", | |
"AuthorComment": "This works even when _m, _n are not compile-time constants.\r\nThis code allocates one big slice for the numbers, plus one slice for _x itself.\r\nThe same function would have to be rewritten, for types other than _float64.", | |
"Version": 3, | |
"VersionDate": "2019-04-06T14:08:34.565013Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1197, | |
"OrigId": 1197, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-01-07T14:11:43.769579Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "const int m = 2;\r\nconst int n = 3;\r\ndouble x[m][n];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This works when the values of _m and _n are known at compile time.", | |
"Version": 1, | |
"VersionDate": "2016-01-07T14:11:43.769579Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1258, | |
"OrigId": 1258, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-01-26T02:11:57.962151Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Erlang", | |
"CodeBlock": "X = [{R * 1.0, C * 1.0} || R \u003c- lists:seq(1, M), C \u003c- lists:seq(1, N)].", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=02f3", | |
"DocumentationURL": "http://learnyousomeerlang.com/starting-out-for-real#list-comprehensions", | |
"AuthorComment": "You don't _declare and _initialize in Erlang. This is the closest thing.", | |
"Version": 2, | |
"VersionDate": "2016-01-27T11:02:58.325559Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1504, | |
"OrigId": 1504, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:25:47.887199Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "var x = new double[m, n];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:25:47.887199Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1517, | |
"OrigId": 1517, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T16:50:02.621054Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "X : array (1 .. M, 1 .. N) of Float := (others =\u003e (others =\u003e 1.0));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T16:50:02.621054Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1542, | |
"OrigId": 1542, | |
"Author": "Feifan", | |
"CreationDate": "2016-02-19T14:23:18.096999Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "$x = array();\r\n$x = array_pad($x, m, 1);\r\nfor($i = 0; $i \u003c count($x); $i++){\r\n $x[$i] = array();\r\n $x[$i] = array_pad($x[$i],n,1);\r\n}\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2016-11-04T11:57:03.73348Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1658, | |
"OrigId": 1658, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T06:44:10.666646Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lua", | |
"CodeBlock": "local x = setmetatable({},{\n __index = function(t1,k1)\n t1[k1] = setmetatable({},{\n __index = function(t2,k2)\n t2[k2] = 0\n return t2[k2]\n end\n })\n return t1[k1]\n end\n})", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/e52KGRhA", | |
"DocumentationURL": "http://www.lua.org/pil/11.2.html", | |
"AuthorComment": "2D arrays are tables of tables (tables are hashmaps).\r\n\r\nUse metatable to lazy initialize each row (_t1[_k1]) and each column (_t2[_k2]) the first time it's accessed.\r\n\r\nSee http://www.programming-idioms.org/idiom/27/create-a-3-dimensional-array/1675/lua for a more \"standard\" way.", | |
"Version": 4, | |
"VersionDate": "2018-06-24T10:27:14.764885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2032, | |
"OrigId": 2032, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-13T15:50:52.473998Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(build-list m (lambda (x)\n (build-list n (lambda (y) 0))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The (_lambda (_y) _0) isn't strictly necessary, it just initializes the values in the matrix to 0.", | |
"Version": 1, | |
"VersionDate": "2017-06-13T15:50:52.473998Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2304, | |
"OrigId": 2304, | |
"Author": "fantasy", | |
"CreationDate": "2018-05-08T00:39:09.948085Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::vector\u003cstd::vector\u003cdouble\u003e \u003e x (m, std::vector\u003cdouble\u003e (n));\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-08-05T12:06:47.277838Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cvector\u003e\r\n", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2318, | |
"OrigId": 2318, | |
"Author": "Aquamo", | |
"CreationDate": "2018-05-09T01:34:05.087686Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let mut x = [[0.0; N] ; M];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?gist=a25a0b7137c8f5c8d0534614b5996830\u0026version=stable\u0026mode=debug", | |
"DocumentationURL": "", | |
"AuthorComment": "This works only when _M and _N are constant.\r\nElements have type _f64", | |
"Version": 4, | |
"VersionDate": "2018-05-10T09:31:28.988317Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2453, | |
"OrigId": 2453, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T14:07:44.114601Z", | |
"LastEditor": "devbg", | |
"LanguageName": "JS", | |
"CodeBlock": "const x = new Array(m).fill(new Array(n).fill(Math.random()));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-11-09T14:07:44.114601Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2461, | |
"OrigId": 2461, | |
"Author": "feng", | |
"CreationDate": "2018-11-29T01:42:45.201747Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scala", | |
"CodeBlock": "val x = Array.ofDim[Double](m,n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-12-02T14:16:43.612474Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2618, | |
"OrigId": 2618, | |
"Author": "Alexander", | |
"CreationDate": "2019-02-16T07:47:09.935551Z", | |
"LastEditor": "Alexander", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(for [i (range 1 (inc m))]\n (for [j (range 1 (inc n))]\n (* i j)))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Creates an _m by _n matrix filled with the multiplication table for 1 to _m by 1 to _n (inclusive)", | |
"Version": 5, | |
"VersionDate": "2019-02-16T07:58:56.994239Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2622, | |
"OrigId": 2622, | |
"Author": "JohanW", | |
"CreationDate": "2019-03-08T10:10:46.774323Z", | |
"LastEditor": "JohanW", | |
"LanguageName": "Elixir", | |
"CodeBlock": "x = for _ \u003c- 1..m, do: for _ \u003c- 1..n, do: 0.0", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://hexdocs.pm/elixir/Kernel.SpecialForms.html#for/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-03-08T10:10:46.774323Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2799, | |
"OrigId": 2799, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:18:35.822272Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(make-array (list m n)\n :element-type 'double-float\n :initial-element 1.0d0)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:18:35.822272Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2935, | |
"OrigId": 2935, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T17:12:36.340404Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " real, dimension(n,m) :: x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:12:36.340404Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2966, | |
"OrigId": 2966, | |
"Author": "munk-a", | |
"CreationDate": "2019-09-26T17:37:51.724409Z", | |
"LastEditor": "munk-a", | |
"LanguageName": "PHP", | |
"CodeBlock": "$m = 3;\n$n = 4;\n\n$x = array_map(\n function () use ($m) { return array_fill(0, $m, 0); },\n range(1, $n)\n);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/CCJcc", | |
"DocumentationURL": "", | |
"AuthorComment": "PHP is pretty lackadaisical about forward declarations, but this is a clean functional approach to bang one out pretty painlessly.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:37:51.724409Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3012, | |
"OrigId": 3012, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T18:44:20.588069Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val x = Array(m, { DoubleArray(n) })\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The type of x is Array\u003cDoubleArray\u003e. In other words, an array of arrays.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T18:44:20.588069Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 30, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
27 | |
], | |
"RelatedIdiomTitles": [ | |
"Create a 3-dimensional array" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 27, | |
"OrigId": 0, | |
"Title": "Create a 3-dimensional array", | |
"LeadParagraph": "Declare and initialize a 3D array _x, having dimensions boundaries _m, _n, _p, and containing real numbers.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[C] sizeof(double) doesn't have to be equal to sizeof(double *); sizeof(double *) -\u003e sizeof(double **) change is cosmetics. ", | |
"LastEditedImplID": 479, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/27/3D-matrix.png", | |
"Version": 37, | |
"VersionDate": "2019-09-27T21:45:13.873211Z", | |
"Implementations": [ | |
{ | |
"Id": 111, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "double[][][] x = new double[m][n][p];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/0RjsYb", | |
"DocumentationURL": "", | |
"AuthorComment": "Initial values are 0.0\r\n_m, _n, _p need not be known at compile time", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 145, | |
"OrigId": 145, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "const m, n, p = 2, 2, 3\r\nvar x [m][n][p]float64", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/BMuuwLrp0q", | |
"DocumentationURL": "", | |
"AuthorComment": "_m, _n, _p must be constant for this syntax to be valid.\r\nHere _x is of type [2][2][3]float64, it is not a slice.", | |
"Version": 2, | |
"VersionDate": "2015-12-30T17:14:12.167827Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 192, | |
"OrigId": 192, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "x = [[[0 for k in xrange(p)] for j in xrange(n)] for i in xrange(m)]", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/10668448/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 193, | |
"OrigId": 193, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "x = numpy.zeros((m,n,p))", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/10668448/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "NumPy is a third-party library for scientific computing.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import numpy", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 452, | |
"OrigId": 452, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "let x = vec![vec![vec![0.0f64; P]; N]; M];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/bgzAzQ", | |
"DocumentationURL": "", | |
"AuthorComment": "You can also use stack-allocated arrays for this: `let x = [[[0.0f64; P]; N]; M];`", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 479, | |
"OrigId": 479, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "skogtwin", | |
"LanguageName": "C", | |
"CodeBlock": "double ***x=malloc(m*sizeof(double **));\nint i,j;\nfor(i=0;i\u003cm;i++)\n{\n\tx[i]=malloc(n*sizeof(double *));\n\tfor(j=0;j\u003cn;j++)\n\t{\n\t\tx[i][j]=malloc(p*sizeof(double));\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Uses dynamic allocation.\r\n\r\nIf the values of m and n are known at compile time you can also use:\r\n\r\ndouble x[m][n][p];", | |
"Version": 2, | |
"VersionDate": "2019-09-27T21:45:13.868403Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 566, | |
"OrigId": 566, | |
"Author": "schveiguy", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "schveiguy", | |
"LanguageName": "D", | |
"CodeBlock": "auto x = new real[][][](m, n, p);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "multi-dim array initialization cannot put dimensions inside the brackets, it must be done this way.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 662, | |
"OrigId": 662, | |
"Author": "Varianus", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "Varianus", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var x: array [m,n,p] of double;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 738, | |
"OrigId": 738, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "var x = new List.generate(m, (_) =\u003e \n new List.generate(n, (_) =\u003e \n new List.filled(p, 0.0), \n growable: false), \n growable: false);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:core.List#id_List-generate", | |
"AuthorComment": "Dart does not have multidimensional arrays as a primitive, this is a list of lists of lists of doubles, all fixed-length lists.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 878, | |
"OrigId": 878, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x = Array.new(m) { Array.new(n) { Array.new(p) } }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 963, | |
"OrigId": 963, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.593658Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "x = [ [ [ k**(i/j) | k\u003c-[1..p] ] | j\u003c-[1..n] ] | i\u003c-[1..m] ]\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.593658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1160, | |
"OrigId": 1160, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-12-30T17:26:25.70947Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func make3D(m, n, p int) [][][]float64 {\r\n\tbuf := make([]float64, m*n*p)\r\n\r\n\tx := make([][][]float64, m)\r\n\tfor i := range x {\r\n\t\tx[i] = make([][]float64, n)\r\n\t\tfor j := range x[i] {\r\n\t\t\tx[i][j] = buf[:p:p]\r\n\t\t\tbuf = buf[p:]\r\n\t\t}\r\n\t}\r\n\treturn x\r\n}", | |
"OriginalAttributionURL": "https://golang.org/doc/effective_go.html#two_dimensional_slices", | |
"DemoURL": "http://play.golang.org/p/AL5GBCgYTM", | |
"DocumentationURL": "", | |
"AuthorComment": "This works even when m, n, p are not compile-time constants.\r\nThis code allocates one big slice for the numbers, then a few slices for intermediate dimensions.\r\nTo same function would be rewritten, for types other than _float64.", | |
"Version": 3, | |
"VersionDate": "2015-12-30T17:51:56.773818Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1521, | |
"OrigId": 1521, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T17:24:17.485163Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "X : array (1 .. M, 1 .. N, 1 .. P) of Float := (others =\u003e (others =\u003e (others =\u003e 1.0)));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T17:24:17.485163Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1593, | |
"OrigId": 1593, | |
"Author": "AgillaDev", | |
"CreationDate": "2016-03-02T14:27:10.194564Z", | |
"LastEditor": "AgillaDev", | |
"LanguageName": "PHP", | |
"CodeBlock": "$x = array_fill(0, $m, array_fill(0, $n, array_fill(0,$p,0)));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/function.array-fill.php", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-03-02T14:27:10.194564Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1630, | |
"OrigId": 1630, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-04-05T04:42:46.324133Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "X = array(M, N, P).\r\n\r\n-spec array(pos_integer(), pos_integer(), pos_integer()) -\u003e [[[float()]]].\r\narray(M, N, P) -\u003e [array(M, N) || _ \u003c- lists:seq(1, P)].\r\narray(M, N) -\u003e [array(M) || _ \u003c- lists:seq(1, N)].\r\narray(M) -\u003e [rand:uniform() || _ \u003c- lists:seq(1, M)].", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=78f3", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-04-05T04:44:19.293242Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1675, | |
"OrigId": 1675, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T09:36:53.978282Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "local x = {}\r\nfor i=1,m do\r\n x[i] = {}\r\n for j=1,n do\r\n x[i][j] = {}\r\n for k=1,p do\r\n x[i][j][k] = 0\r\n end\r\n end\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "see http://www.programming-idioms.org/idiom/26/create-a-2-dimensional-array/1658/lua# for a lazy initialization", | |
"Version": 1, | |
"VersionDate": "2016-04-07T09:36:53.978282Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2312, | |
"OrigId": 2312, | |
"Author": "fantasy", | |
"CreationDate": "2018-05-08T01:34:15.772091Z", | |
"LastEditor": "fantasy", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::vector\u003cstd::vector\u003cstd::vector\u003cdouble\u003e\u003e\u003e x (m, std::vector\u003cstd::vector\u003cdouble\u003e\u003e (n, std::vector\u003cdouble\u003e (p)));\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-05-08T01:34:15.772091Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cvector\u003e\r\n", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2377, | |
"OrigId": 2377, | |
"Author": "dmaestro", | |
"CreationDate": "2018-08-18T20:39:49.890252Z", | |
"LastEditor": "MarkFowler", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $array3d = [\n [ [ 1, 0, 1 ],\n [ 0, 0, 0 ],\n [ 1, 0, 1 ] ],\n [ [ 0, 0, 0 ],\n [ 0, 2, 0 ],\n [ 0, 0, 0 ] ],\n [ [ 3, 0, 3, ],\n [ 0, 0, 0, ],\n [ 3, 0, 3, ] ]\n];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://perldoc.perl.org/perllol.html", | |
"AuthorComment": "Array variables are only one-dimensional, but arrays-of-arrays using _array _references can represent multi-dimensional arrays.", | |
"Version": 3, | |
"VersionDate": "2019-09-26T15:46:35.959635Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2454, | |
"OrigId": 2454, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T14:10:25.382756Z", | |
"LastEditor": "devbg", | |
"LanguageName": "JS", | |
"CodeBlock": "const x = new Array(m).fill(\n new Array(n).fill(\n new Array(p).fill(Math.random())\n )\n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-11-09T14:10:25.382756Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2737, | |
"OrigId": 2737, | |
"Author": "cskwrd", | |
"CreationDate": "2019-09-26T14:27:11.444826Z", | |
"LastEditor": "cskwrd", | |
"LanguageName": "Csharp", | |
"CodeBlock": "var multidimensionalArray = new double[m, n, p];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dotnetfiddle.net/rC7w7z", | |
"DocumentationURL": "https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/multidimensional-arrays", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:27:11.444826Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2825, | |
"OrigId": 2825, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:42:48.09394Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defparameter *x*\n (make-array (list m n p)\n :element-type 'double-float\n :initial-element 0.0d0))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:42:48.09394Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2910, | |
"OrigId": 2910, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:58:50.608388Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " real, dimension(:,:,:), allocatable :: x\n\n allocate (x(m,n,p))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:58:50.608388Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 22, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
26 | |
], | |
"RelatedIdiomTitles": [ | |
"Create a 2-dimensional array" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 28, | |
"OrigId": 0, | |
"Title": "Sort by a property", | |
"LeadParagraph": "Sort elements of array-like collection _items in ascending order of _x._p, where _p is a field of the type _Item of the objects in _items.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[PHP] Fix explanation box (bad underscore)", | |
"LastEditedImplID": 1533, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 51, | |
"VersionDate": "2019-09-27T09:52:52.674489Z", | |
"Implementations": [ | |
{ | |
"Id": 112, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "Arrays.sort(items, new Comparator\u003cItem\u003e(){\r\n\tpublic int compare(Item a, Item b){\r\n\t\treturn a.p - b.p;\r\n\t}\r\n});", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/gqNVEH", | |
"DocumentationURL": "https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#sort(T[],%20java.util.Comparator)", | |
"AuthorComment": "_items is an array of type _Item[].\r\nUse an anonymous class which implements _Comparator\u003c_Item\u003e", | |
"Version": 2, | |
"VersionDate": "2016-12-11T21:15:01.524159Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Arrays;\r\nimport java.util.Comparator;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 160, | |
"OrigId": 160, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "type ItemPSorter []Item\nfunc (s ItemPSorter) Len() int{ return len(s) }\nfunc (s ItemPSorter) Less(i,j int) bool{ return s[i].p\u003cs[j].p }\nfunc (s ItemPSorter) Swap(i,j int) { s[i],s[j] = s[j],s[i] }\n\nfunc sortItems(items []Item){\n\tsorter := ItemPSorter(items)\n\tsort.Sort(sorter)\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/t7R2h5kzwJ", | |
"DocumentationURL": "", | |
"AuthorComment": "The standard way is to declare a new type _ItemSorter as a slice of _Item, and carefully implement method _Less.", | |
"Version": 3, | |
"VersionDate": "2018-02-14T12:52:36.590587Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"sort\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 264, | |
"OrigId": 264, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "Collections.sort(items, new Comparator\u003cItem\u003e(){\r\n\t@Override\r\n\tpublic int compare(Item a, Item b){\r\n\t\treturn a.p - b.p;\r\n\t}\r\n});", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html", | |
"AuthorComment": "_items is a _List\u003c_Item\u003e.\r\nUse an anonymous class which implements _Comparator\u003c_Item\u003e.", | |
"Version": 2, | |
"VersionDate": "2016-12-11T20:49:52.448302Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Collections;\r\nimport java.util.Comparator;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 275, | |
"OrigId": 275, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "items.sort(function(a,b) {\n return compareFieldP(a.p, b.p);\n});", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/979289/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Implements your own _compareFieldP depending on the type of _p.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 307, | |
"OrigId": 307, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "@items = sort { $a-\u003e{p} cmp $b-\u003e{p} } @items;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "sort gives your code block two items to sort: $a and $b. Two operators are commonly used: cmp to sort lexically, and \u003c=\u003e to sort numerically. Swapping the positions of $a and $b reverses the sort direction.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 350, | |
"OrigId": 350, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Python", | |
"CodeBlock": "items = sorted(items, key=lambda x: x.p)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The lambda expression pulls out the field you want to sort by. If you want to sort in reverse order, add reverse=True to the argument list.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 476, | |
"OrigId": 476, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "Rust", | |
"CodeBlock": "items.sort_by(|a,b|a.p.cmp(\u0026b.p));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 550, | |
"OrigId": 550, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "sort!(\"a.p \u003c b.p\")(items);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm.sorting;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 634, | |
"OrigId": 634, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "items.sort((a, b) =\u003e Comparable.compare(a.p, b.p));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/e257952adde1efa570c3", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 729, | |
"OrigId": 729, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "items.sort((a, b) =\u003e (a.p).compareTo(b.p));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 755, | |
"OrigId": 755, | |
"Author": "Geep Jeez", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "Geep Jeez", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type\n\n TItem = class p: Integer; end;\n TItems = specialize TFPGObjectList\u003cTItem\u003e;\n\nvar items: TItems;\n\n function compare(const a, b: TItem): Integer;\n begin\n Result := a.p - b.p;\n end;\n\nbegin\n items := TItems.Create;\n // Add items here.\n items.Sort(@compare);\nend. ", | |
"OriginalAttributionURL": "http://wiki.freepascal.org/Generics#fgl_unit", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses fgl;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 817, | |
"OrigId": 817, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "sort_by_birth(ListOfMaps) -\u003e\n lists:sort(\n fun(A, B) -\u003e\n maps:get(birth, A, undefined) =\u003c maps:get(birth, B, undefined)\n end, ListOfMaps).\n\nsort_by_birth(ListOfRecords) -\u003e lists:keysort(#item.birth, ListOfRecords).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://www.tryerlang.org/", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=5\u0026search=lists#undefined", | |
"AuthorComment": "First function works with a list of maps, like [#{birth =\u003e \"1982-01-03\"}, …].\r\nSecond function works with a list of records, like [#item{birth = \"1982-01-03\", …}, …]", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "\t", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 831, | |
"OrigId": 831, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "sortBy (comparing p) items", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 835, | |
"OrigId": 835, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.sort_by(\u0026:p)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-sort_by", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.658885Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 929, | |
"OrigId": 929, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:27.658885Z", | |
"LastEditor": "mru2", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Enum.sort_by(items, \u0026(\u00261.p))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/9ab4ff24fb", | |
"DocumentationURL": "https://hexdocs.pm/elixir/Enum.html#sort_by/3", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-02-14T15:39:34.774628Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1341, | |
"OrigId": 1341, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T17:07:55.54585Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "table.sort(items, function(a,b)\r\n\tif a.p \u003c b.p then return true end\r\nend)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:07:55.54585Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1377, | |
"OrigId": 1377, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T18:34:47.159739Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::sort(begin(items), end(items), [](const auto\u0026 a, const auto\u0026 b) { return a.p \u003c b.p; });", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/algorithm/sort", | |
"AuthorComment": "This sort is not a stable sort.", | |
"Version": 1, | |
"VersionDate": "2016-02-16T18:34:47.159739Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003calgorithm\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1449, | |
"OrigId": 1449, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:58:32.203395Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "case class S(x: Int)\r\nval items = List(S(3), S(4), S(2))\r\nitems.sortBy( item: S =\u003e item.x )", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:58:32.203395Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1498, | |
"OrigId": 1498, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:15:03.148685Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Array.Sort(items, (a, b) =\u003e compareFunc(a.p, b.p));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:15:03.148685Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1515, | |
"OrigId": 1515, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T16:25:43.53535Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "declare\r\n function Compare_Function (Left, Right : Item) return Boolean is (Left.P \u003c Right.P);\r\n \r\n package Item_Vector_Sorting is new Item_Vectors.Generic_Sorting (Compare_Function);\r\n\r\n use Item_Vector_Sorting;\r\nbegin\r\n Sort (Items);\r\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T16:25:43.53535Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Containers.Vectors;\r\nuse Ada.Containers;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1533, | |
"OrigId": 1533, | |
"Author": "nvius", | |
"CreationDate": "2016-02-18T15:34:44.360796Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function cmp($a, $b)\n{\n if ($a-\u003ep == $b-\u003ep) {\n return 0;\n }\n\n return ($a-\u003ep \u003c $b-\u003ep) ? -1 : 1;\n}\n\nusort($items, 'cmp');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/OsWlhVpV", | |
"DocumentationURL": "http://php.net/manual/en/function.usort.php", | |
"AuthorComment": "Use of _usort with a custom function _cmp for sorting objects by property.\r\n\r\nUse triple equals ($a-\u003ep === $b-\u003ep) for higher performance if you know the types will be identical.", | |
"Version": 5, | |
"VersionDate": "2019-09-27T09:52:52.671968Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1936, | |
"OrigId": 1936, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-02-23T12:12:42.378736Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "less := func(i, j int) bool {\r\n\treturn items[i].p \u003c items[j].p\r\n}\r\nsort.Slice(items, less)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/jMZ1croPLE", | |
"DocumentationURL": "https://golang.org/pkg/sort/#Slice", | |
"AuthorComment": "This is the diomatic way since Go 1.8.", | |
"Version": 1, | |
"VersionDate": "2017-02-23T12:12:42.378736Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"sort\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1979, | |
"OrigId": 1979, | |
"Author": "TheVTM", | |
"CreationDate": "2017-04-27T11:02:28.085727Z", | |
"LastEditor": "TheVTM", | |
"LanguageName": "Rust", | |
"CodeBlock": "items.sort_by_key(|item| item.p);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?gist=561c0c2b04b7c2329d0dfb8b8413ecea\u0026version=stable\u0026backtrace=0", | |
"DocumentationURL": "https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by_key", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-04-29T06:51:37.60358Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2006, | |
"OrigId": 2006, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-02T15:59:29.141159Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "C", | |
"CodeBlock": "int compareProp (const void *a, const void *b)\n{\n return (*(const Item**)a)-\u003ep - (*(const Item**)b)-\u003ep;\n}\n\nqsort(items, N, sizeof(Item*), compareProp);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_items is an array of _Item* with length _N", | |
"Version": 1, | |
"VersionDate": "2017-06-02T15:59:29.141159Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2620, | |
"OrigId": 2620, | |
"Author": "Alexander", | |
"CreationDate": "2019-02-16T17:39:04.743688Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(sort-by :p items)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojuredocs.org/clojure.core/sort-by", | |
"AuthorComment": "Clojure keywords also act as functions that look up the value of their key in associative data structures", | |
"Version": 2, | |
"VersionDate": "2019-03-26T21:17:14.965112Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2652, | |
"OrigId": 2652, | |
"Author": "morteako", | |
"CreationDate": "2019-07-03T16:05:29.509778Z", | |
"LastEditor": "morteako", | |
"LanguageName": "Haskell", | |
"CodeBlock": "List.sortOn p items", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-07-03T16:05:29.509778Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import qualified Data.List as List", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2846, | |
"OrigId": 2846, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:02:03.057192Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(sort #'\u003c items :key #'p)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:02:03.057192Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2922, | |
"OrigId": 2922, | |
"Author": "Canem Inops ", | |
"CreationDate": "2019-09-26T17:04:15.680973Z", | |
"LastEditor": "Canem Inops ", | |
"LanguageName": "Java", | |
"CodeBlock": "items.stream().sorted(Comparator.comparing(x -\u003e x.p))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:04:15.680973Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Comparator;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3024, | |
"OrigId": 3024, | |
"Author": "zr8c", | |
"CreationDate": "2019-09-26T19:03:20.9487Z", | |
"LastEditor": "zr8c", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "items.sortedBy { it.p }\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T19:04:40.004244Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 29, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
100 | |
], | |
"RelatedIdiomTitles": [ | |
"Sort by a comparator" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 29, | |
"OrigId": 0, | |
"Title": "Remove item from list, by its index", | |
"LeadParagraph": "Remove _i-th item from list _items.\r\nThis will alter the original list or return a new list, depending on which is more idiomatic.\r\nNote that in most languages, the smallest valid value for _i is _0.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[PHP] Format code snippet to PSR-12, added documentation URL", | |
"LastEditedImplID": 463, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 39, | |
"VersionDate": "2019-09-27T10:20:20.004841Z", | |
"Implementations": [ | |
{ | |
"Id": 113, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "items.remove(i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/util/List.html#remove-int-", | |
"AuthorComment": "Original list is altered.\r\n\r\nBe careful not to confuse remove(_int) with remove(_Object), in case you have a _List\u003c_Integer\u003e (conversions can be tricky)", | |
"Version": 2, | |
"VersionDate": "2015-12-01T11:47:57.506253Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.List;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 120, | |
"OrigId": 120, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "items.delete_at(i) ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-1.8.6/Array.html#method-i-delete_at", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 199, | |
"OrigId": 199, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "del items[i]", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/627453/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This alters the original list.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 316, | |
"OrigId": 316, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "# perl alters the original list with splice\n$removed_element = splice @items, $i, 1;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Splice is much more flexible, and can do more.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 368, | |
"OrigId": 368, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "let new_list = items.filter(function(val,idx,ary) { return idx != i });", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-12-16T19:21:45.332113Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 449, | |
"OrigId": 449, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "items.remove(i)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/ZzNFBv", | |
"DocumentationURL": "http://doc.rust-lang.org/std/vec/struct.Vec.html#method.remove", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 463, | |
"OrigId": 463, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "unset($items[$i]);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://www.php.net/unset", | |
"AuthorComment": "// alters original array $items", | |
"Version": 2, | |
"VersionDate": "2019-09-27T10:20:20.002435Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 507, | |
"OrigId": 507, | |
"Author": "bbtemp", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "bbtemp", | |
"LanguageName": "D", | |
"CodeBlock": "items = items.remove(i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm.mutation;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 632, | |
"OrigId": 632, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "items.removeAt(i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/cb8a43ea7440e37e4072", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 656, | |
"OrigId": 656, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "list[i] := list[high(list)];\r\nsetlength(list,high(list));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "2-part Solution:\r\nFirst the element is overwritten by the last element,\r\nThen the list is reduced by one.\r\nThis destroys the original ordering.", | |
"Version": 2, | |
"VersionDate": "2016-02-07T20:54:03.347779Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 940, | |
"OrigId": 940, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "List.delete_at(items, i)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/bb99bc0a34", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/List.html#delete_at/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 958, | |
"OrigId": 958, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.739993Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "take i items ++ drop (1 + i) items", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.739993Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1166, | |
"OrigId": 1166, | |
"Author": "lck", | |
"CreationDate": "2016-01-01T00:24:19.887196Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "items = append(items[:i], items[i+1:]...)", | |
"OriginalAttributionURL": "https://github.com/golang/go/wiki/SliceTricks", | |
"DemoURL": "https://play.golang.org/p/C5d_LrB2e3", | |
"DocumentationURL": "", | |
"AuthorComment": "If _items elements are pointers or structs with pointers, then refer to the SliceTricks page to avoid memory leaks.", | |
"Version": 4, | |
"VersionDate": "2016-06-05T15:15:46.611327Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1260, | |
"OrigId": 1260, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-01-26T02:23:31.613244Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "{Left, [_|Right]} = lists:split(I-1, Items),\r\nLeft ++ Right.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=0df3", | |
"DocumentationURL": "http://erldocs.com/maint/stdlib/lists.html?i=0\u0026search=lists:spl#split/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-01-26T02:23:31.613244Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1506, | |
"OrigId": 1506, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:30:06.367518Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "items.RemoveAt(i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:30:06.367518Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System.Collections.Generic;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1518, | |
"OrigId": 1518, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T16:54:54.195088Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "Items.Delete (I);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T16:54:54.195088Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Containers.Vectors;\r\nuse Ada.Containers;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1662, | |
"OrigId": 1662, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T07:29:03.373354Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "local removedItem = table.remove(items,i)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.lua.org/manual/5.2/manual.html#pdf-table.remove", | |
"AuthorComment": "alter the original list, return the removed element", | |
"Version": 1, | |
"VersionDate": "2016-04-07T07:29:03.373354Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1734, | |
"OrigId": 1734, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-06-05T18:07:35.337765Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "copy(items[i:], items[i+1:])\r\nitems[len(items)-1] = nil\r\nitems = items[:len(items)-1]", | |
"OriginalAttributionURL": "https://github.com/golang/go/wiki/SliceTricks", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This code is for pointer value type, and has no memory leak.", | |
"Version": 1, | |
"VersionDate": "2016-06-05T18:07:35.337765Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2132, | |
"OrigId": 2132, | |
"Author": "knoerriefast", | |
"CreationDate": "2017-10-21T05:58:01.464795Z", | |
"LastEditor": "knoerriefast", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (removeElementByIndex L i)\n (if (null? L)\n null\n (if (= i 0)\n (cdr L)\n (cons (car L) (removeElementByIndex (cdr L) (- i 1)))\n )\n )\n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-10-21T05:58:01.464795Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2311, | |
"OrigId": 2311, | |
"Author": "fantasy", | |
"CreationDate": "2018-05-08T01:31:43.89217Z", | |
"LastEditor": "fantasy", | |
"LanguageName": "Cpp", | |
"CodeBlock": "items.erase (items.begin () + i);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-05-08T01:31:43.89217Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2455, | |
"OrigId": 2455, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T14:13:50.372418Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "items.splice(i,1);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "this will modify the original list (kinda)", | |
"Version": 2, | |
"VersionDate": "2018-12-16T19:21:23.432824Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3081, | |
"OrigId": 3081, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:30:33.861852Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "integer, allocatable, dimension(:) :: items\nitems = [items(:i-1), items(i+1:)]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This uses the Fortran feature of reallocation on assignment.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:30:33.861852Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 22, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
135 | |
], | |
"RelatedIdiomTitles": [ | |
"Remove item from list, by its value" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 30, | |
"OrigId": 0, | |
"Title": "Parallelize execution of 1000 independent tasks", | |
"LeadParagraph": "Launch the concurrent execution of procedure _f with parameter _i from 1 to 1000.\r\nTasks are independent and _f(_i) doesn't return any value.\r\nTasks need not run all at the same time, so you may use a pool.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Java] added final", | |
"LastEditedImplID": 218, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 29, | |
"VersionDate": "2019-09-26T19:21:23.804537Z", | |
"Implementations": [ | |
{ | |
"Id": 114, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "maerf0x0", | |
"LanguageName": "Go", | |
"CodeBlock": "wg := sync.WaitGroup{}\nwg.Add(1000)\nfor i := 1; i \u003c= 1000; i++ {\n\tgo func(j int) {\n f(j)\n wg.Done()\n }(i)\n}\nwg.Wait()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/I5LBz1aSep", | |
"DocumentationURL": "https://godoc.org/sync#WaitGroup", | |
"AuthorComment": "The current value of _i is captured, and a goroutine is launched", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:51:59.084374Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"sync\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 189, | |
"OrigId": 189, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "pool = Pool()\nfor i in range(1, 1001):\n\tpool.apply_async(f, [i])", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/20548628/how-to-do-parallel-programming-in-python/20549090#20549090", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "from multiprocessing import Pool", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 218, | |
"OrigId": 218, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "yusufaytas", | |
"LanguageName": "Java", | |
"CodeBlock": "final ExecutorService executor = Executors.newFixedThreadPool(NB_THREADS);\nfor (int i = 1; i \u003c= 1000; i++) {\n executor.submit(() -\u003e f(i));\n}\nexecutor.shutdown();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "For a large number of tasks, use a thread pool.", | |
"Version": 3, | |
"VersionDate": "2019-09-26T19:21:23.80186Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.concurrent.ExecutorService;\r\nimport java.util.concurrent.Executors;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 351, | |
"OrigId": 351, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "for my $i (1 .. 1000) {\n threads-\u003ecreate('f', $i);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Note: The threads library will warn you at the end of the program if you don't join or detach each thread.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use threads;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 409, | |
"OrigId": 409, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "let threads: Vec\u003c_\u003e = (0..1000).map(|i| {\n\tthread::spawn(move || f(i))\n}).collect();\n\nfor thread in threads {\n\tthread.join();\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "If you don't join the threads, the program will just exit and the threads will be killed.\r\n\r\nThis would be better implemented with a thread pool but the standard library doesn't include one.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::thread;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 518, | |
"OrigId": 518, | |
"Author": "jwhear", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "taskPool.amap!f(iota(1, 1001));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_iota produces a lazy sequence from the start parameter up to (but not including) the end parameter.\r\n\r\n_taskPool._amap performs an eager mapping over the supplied sequence using the default thread pool.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.parallelism;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 759, | |
"OrigId": 759, | |
"Author": "Geep Jeez", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "Geep Jeez", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type\n\nTThreadF = class(TThread)\n i: Integer;\n constructor Create(const _i: Integer);\n procedure Execute; override;\nend;\n\nconstructor TThreadF.Create(const _i: Integer);\nbegin\n i := _i;\n FreeOnTerminate := True;\n inherited Create(False);\nend;\n\nprocedure TThreadF.Execute;\nbegin\n f(i);\nend;\n\nvar i: Integer;\n\nbegin\n for i := 1 to 1000 do begin TThreadF.Create(i);\n ReadLn;\nend. ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.freepascal.org/docs-html/rtl/classes/tthread.html", | |
"AuthorComment": "No simple thread pooling in Pascal. Indy components have thread pooling classes.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses Classes;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 787, | |
"OrigId": 787, | |
"Author": "alexv19", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "alexv19", | |
"LanguageName": "Haskell", | |
"CodeBlock": "mapM_ (forkIO . f) [1..1000]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "import Control.Concurrent", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 822, | |
"OrigId": 822, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "lists:foreach(fun(I) -\u003e spawn(?MODULE, _f, [I]) end, lists:seq(1, 1000)).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/current/erts/erlang.html?i=3\u0026search=spawn#spawn/3", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 881, | |
"OrigId": 881, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:58.435578Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "threads = 1000.times.map do |i|\n Thead.new { f(i) }\nend\nthreads.join", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.435578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2332, | |
"OrigId": 2332, | |
"Author": "GobbleCock", | |
"CreationDate": "2018-06-11T22:07:36.699297Z", | |
"LastEditor": "GobbleCock", | |
"LanguageName": "Rust", | |
"CodeBlock": "(0..1000).into_par_iter().for_each(f);", | |
"OriginalAttributionURL": "https://docs.rs/rayon/1.0.1/rayon/iter/trait.ParallelIterator.html#examples", | |
"DemoURL": "https://play.rust-lang.org/?gist=8cf4ac4698d8e5232051b8b8cc3bffdf\u0026version=stable\u0026mode=debug", | |
"DocumentationURL": "https://docs.rs/rayon/1.0.1/rayon/iter/trait.ParallelIterator.html#method.for_each", | |
"AuthorComment": "Requires the rayon crate.\r\n(https://crates.io/crates/rayon)", | |
"Version": 1, | |
"VersionDate": "2018-06-11T22:07:36.699297Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extern crate rayon;\r\nuse rayon::prelude::*;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2773, | |
"OrigId": 2773, | |
"Author": "dirtv", | |
"CreationDate": "2019-09-26T14:55:24.142766Z", | |
"LastEditor": "bluesky", | |
"LanguageName": "JS", | |
"CodeBlock": "for (let i = 1; i \u003c= 1000; i++) setTimeout(() =\u003e f(i), 0);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T18:22:42.903319Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2898, | |
"OrigId": 2898, | |
"Author": "Hueho", | |
"CreationDate": "2019-09-26T16:50:44.419135Z", | |
"LastEditor": "Hueho", | |
"LanguageName": "Elixir", | |
"CodeBlock": "f = fn x -\u003e x * :rand.uniform() end\n\ntasks = Enum.map(1..1000, fn i -\u003e\n Task.async(fn -\u003e\n f.(i)\n end)\nend)\n\nresults = Task.yield_many(tasks, :infinity)\n\n# Optional, if you care for the result\nIO.inspect Enum.map(results, fn {_, {:ok, val}} -\u003e val end)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://hexdocs.pm/elixir/Task.html", | |
"AuthorComment": "_async creates a parallel task.\r\n\r\n_yield_many awaits on many given tasks for a given time. By default it timeouts on 5 seconds, and timed-out tasks will keep running. Passing :infinite as the second argument disables the timeout and blocks the caller indefinitely.\r\n\r\n_yield_many always returns a list of pairs, with the task and the possible return value, either a tuple of :ok and the returned value, a tuple of :error and the reason for it, or nil if the task timed out.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:56:55.09084Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3003, | |
"OrigId": 3003, | |
"Author": "bluesky", | |
"CreationDate": "2019-09-26T18:24:24.525344Z", | |
"LastEditor": "bluesky", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Parallel.For(1, 1001, i =\u003e { F(i); });", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T19:15:54.687491Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System.Threading.Tasks;", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 14, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
56 | |
], | |
"RelatedIdiomTitles": [ | |
"Launch 1000 parallel tasks and wait for completion" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 31, | |
"OrigId": 0, | |
"Title": "Recursive factorial (simple)", | |
"LeadParagraph": "Create recursive function _f which returns the factorial of non-negative integer _i, calculated from _f(_i-1)", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[PHP] Format code snippet to PSR-12", | |
"LastEditedImplID": 2718, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 55, | |
"VersionDate": "2019-09-26T22:27:27.480744Z", | |
"Implementations": [ | |
{ | |
"Id": 117, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "int f(int i){\n\tif(i==0)\n\t\treturn 1;\n\telse\n\t\treturn i * f(i-1);\n} ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/G8eCnz", | |
"DocumentationURL": "", | |
"AuthorComment": "Warnings :\r\n- type _int quickly overflows\r\n- high number of recursive calls may cause a stack overflow\r\n- also, _f is not tail-recursive", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 188, | |
"OrigId": 188, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "def f(i):\n if i == 0:\n return 1\n else:\n return i * f(i-1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 212, | |
"OrigId": 212, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "uint factorial(in uint n) pure nothrow @nogc\nin {\n assert(n \u003c= 12);\n} body {\n if (n == 0)\n return 1;\n else\n return n * factorial(n - 1);\n}", | |
"OriginalAttributionURL": "http://rosettacode.org/wiki/Factorial#Recursive_Version", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Assertion is used to prevent silent overflow.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 317, | |
"OrigId": 317, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub f {\n my $n = shift;\n return $n\u003c2 ? 1 : $n * f($n-1);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 369, | |
"OrigId": 369, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "function f(n) {\n return n\u003c2 ? 1 : n * f(n-1);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 450, | |
"OrigId": 450, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn f(n: u32) -\u003e u32 {\n if n \u003c 2 {\n 1\n } else {\n n * f(n - 1)\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/ZVwM65", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 480, | |
"OrigId": 480, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "Rome", | |
"LanguageName": "C", | |
"CodeBlock": "unsigned int f(unsigned int i)\n{\n\treturn i?i*f(i-1):1;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Overflows for _i\u003e20 in 64bits and for _i\u003e12 in 32bits\r\n", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 696, | |
"OrigId": 696, | |
"Author": "Bart", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "type\n TPositiveInt = 0..MaxInt;\n\nfunction _f(_i: TPositiveInt): Integer;\nbegin\n if (_i \u003c 2) then\n Result := 1\n else\n Result := _f(_i - 1);\nend; ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The definition of type _TPositiveInt allows for rangechecking on the input.\r\n_MaxInt is already defined in the language.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 739, | |
"OrigId": 739, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "f(i) =\u003e (i == 0) ? 1 : i * f(i - 1);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 888, | |
"OrigId": 888, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "f = Hash.new { |hash, i| hash[i] = i * hash[i -1] }\r\nf[0] = 1\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Note that _f is not a function but plain old _Hash used as a cache for performance.", | |
"Version": 3, | |
"VersionDate": "2017-03-19T20:58:32.837709Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 943, | |
"OrigId": 943, | |
"Author": "anandubajith", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "defmodule Factorial do\r\n def of(0), do: 1\r\n def of(n) when n \u003e 0 do\r\n n * of(n-1)\r\n end\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/90405f986e", | |
"DocumentationURL": "", | |
"AuthorComment": "_iex \u003e Factorial.of(100)", | |
"Version": 3, | |
"VersionDate": "2016-11-30T22:20:50.241509Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 944, | |
"OrigId": 944, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.869482Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "f i = if i \u003e 1 then f (i-1) * i else 1\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.869482Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1167, | |
"OrigId": 1167, | |
"Author": "lck", | |
"CreationDate": "2016-01-01T00:27:18.572245Z", | |
"LastEditor": "lck", | |
"LanguageName": "Go", | |
"CodeBlock": "func f(i int) int {\r\n if i == 0 {\r\n return 1\r\n }\r\n return i * f(i-1)\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-01-01T00:27:18.572245Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1261, | |
"OrigId": 1261, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-01-26T02:26:09.420611Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Erlang", | |
"CodeBlock": "f(0) -\u003e 1;\r\nf(I) -\u003e I * f(I - 1).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=0cf3", | |
"DocumentationURL": "", | |
"AuthorComment": "No \"defensive programming\" here.", | |
"Version": 3, | |
"VersionDate": "2016-01-27T11:05:36.776191Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1520, | |
"OrigId": 1520, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T16:59:13.831156Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "function F (I : Natural) return Natural is (if I \u003c 2 then 1 else I * F (I - 1));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-02-17T17:00:00.232204Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1523, | |
"OrigId": 1523, | |
"Author": "everyday847", | |
"CreationDate": "2016-02-17T18:00:11.390869Z", | |
"LastEditor": "everyday847", | |
"LanguageName": "Cpp", | |
"CodeBlock": "unsigned int f( unsigned int i ) {\r\n\tif ( i == 0 ) return 1;\r\n\t\r\n\treturn i * f( i - 1 )\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T18:00:11.390869Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1543, | |
"OrigId": 1543, | |
"Author": "AgillaDev", | |
"CreationDate": "2016-02-19T14:58:25.409733Z", | |
"LastEditor": "jesusflores.dev", | |
"LanguageName": "PHP", | |
"CodeBlock": "function f($i) {\n\tif($i == 0) {\n\t\treturn 1;\n\t}\n\n\treturn ($i * f($i-1));\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2019-09-26T14:44:00.038546Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1659, | |
"OrigId": 1659, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T06:53:49.645085Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "function f(n)\r\n local function f_(factorial,n)\r\n if n \u003c 2 then return 1\r\n return f_(factorial*n, n-1)\r\n end\r\n return f_(1,n)\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/HlGajPjE", | |
"DocumentationURL": "http://lua-users.org/wiki/ProperTailRecursion", | |
"AuthorComment": "proper tail recursion", | |
"Version": 1, | |
"VersionDate": "2016-04-07T06:53:49.645085Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1946, | |
"OrigId": 1946, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-03-19T20:56:31.11298Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "fac = Hash.new {|h, i| h[i] = i * h[i-1] }.tap {|h| h[0] = 1 }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-03-19T20:56:31.11298Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2033, | |
"OrigId": 2033, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-14T15:08:13.080942Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (f i)\n (if (\u003e i 1)\n (* (f (- i 1)) i)\n 1))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-14T15:08:13.080942Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2195, | |
"OrigId": 2195, | |
"Author": "anon20171221", | |
"CreationDate": "2017-12-21T02:59:25.303336Z", | |
"LastEditor": "anon20171221", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(defn f [i]\n (loop [cnt i, acc 1N]\n (if (zero? cnt) acc\n (recur (dec cnt) (* cnt acc)))))\n", | |
"OriginalAttributionURL": "https://clojuredocs.org/clojure.core/recur#example-542692d0c026201cdc326ea6", | |
"DemoURL": "https://ideone.com/wk8obN", | |
"DocumentationURL": "https://clojuredocs.org/clojure.core/recur#example-542692d0c026201cdc326ea6", | |
"AuthorComment": "This supports arbitrary-precision and self tail call optimization.", | |
"Version": 4, | |
"VersionDate": "2017-12-21T03:23:16.225762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2667, | |
"OrigId": 2667, | |
"Author": "erlend.powell", | |
"CreationDate": "2019-07-06T11:24:07.883366Z", | |
"LastEditor": "erlend.powell", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn factorial(num: u64) -\u003e u64 {\n match num {\n 0 =\u003e 1,\n 1 =\u003e 1,\n _ =\u003e factorial(num - 1) * num,\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-07-06T11:24:52.220646Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2694, | |
"OrigId": 2694, | |
"Author": "dingo", | |
"CreationDate": "2019-09-26T13:46:32.619149Z", | |
"LastEditor": "dingo", | |
"LanguageName": "Csharp", | |
"CodeBlock": "private static int Factorial(int n) {\n if (n == 0) return 1;\n return n * Factorial(n - 1);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T13:46:32.619149Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2712, | |
"OrigId": 2712, | |
"Author": "taus", | |
"CreationDate": "2019-09-26T13:57:01.536588Z", | |
"LastEditor": "taus", | |
"LanguageName": "Scala", | |
"CodeBlock": "def f(i: Int): Int =\n if (i \u003e 1){\n i * f(i-1) \n } else{\n 1\n }", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T13:57:01.536588Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2718, | |
"OrigId": 2718, | |
"Author": "nek", | |
"CreationDate": "2019-09-26T14:01:55.823462Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function f(int $i): int\n{\n if ($i == 0) {\n return 1;\n }\n\n return $i * f($i - 1);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:27:27.477685Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2750, | |
"OrigId": 2750, | |
"Author": "f", | |
"CreationDate": "2019-09-26T14:36:02.018224Z", | |
"LastEditor": "f", | |
"LanguageName": "JS", | |
"CodeBlock": "const fact = n =\u003e n === 0 ? 1 : n * fact(n-1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:36:02.018224Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2780, | |
"OrigId": 2780, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:02:19.840561Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defun f (i)\n (if (\u003c i 2)\n 1\n (* i (f (- i 1)))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:02:19.840561Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3034, | |
"OrigId": 3034, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T19:25:06.241936Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "module x\n implicit none\ncontains\n recursive function fac (n) result (res)\n integer, intent(in) :: n\n integer :: res\n if (n \u003c= 0) then\n res = 1\n else\n res = fac(n-1) * n\n end if\n end function fac\nend module x", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:25:06.241936Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3118, | |
"OrigId": 3118, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T21:54:17.53258Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "fun f(i: Int): Int = when (i) {\n 0 -\u003e 1\n else -\u003e i * f(i - 1)\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:54:17.53258Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3119, | |
"OrigId": 3119, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T21:54:41.981207Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "fun f(i: Int) = if (i == 0) 1 else i * f(i - 1)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T21:54:41.981207Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 30, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 32, | |
"OrigId": 0, | |
"Title": "Integer exponentiation by squaring", | |
"LeadParagraph": "Create function _exp which calculates (fast) the value _x power _n.\r\n_x and _n are non-negative integers.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [jupiter]", | |
"LastEditedImplID": 3213, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 48, | |
"VersionDate": "2019-09-27T09:18:16.706137Z", | |
"Implementations": [ | |
{ | |
"Id": 118, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "int exp(int x, int n){\n\tif(n==0)\n\t\treturn 1;\n\tif(n==1)\n\t\treturn x;\n\tif(n%2==0)\n\t\treturn exp(x*x, n/2);\n\telse\n\t\treturn x * exp(x*x, (n-1)/2);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/0lcLdY", | |
"DocumentationURL": "", | |
"AuthorComment": "Warning :\r\n- type _int quickly overflows", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 196, | |
"OrigId": 196, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "ExpHP", | |
"LanguageName": "Python", | |
"CodeBlock": "def exp(x, n):\r\n return x**n\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-06-13T00:14:23.672291Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 278, | |
"OrigId": 278, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func exp(x, n int) int {\n\tswitch {\n\tcase n == 0:\n\t\treturn 1\n\tcase n == 1:\n\t\treturn x\n\tcase n%2 == 0:\n\t\treturn exp(x*x, n/2)\n\tdefault:\n\t\treturn x * exp(x*x, (n-1)/2)\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/v_8_hZrnkT", | |
"DocumentationURL": "", | |
"AuthorComment": "Warning :\r\n- type _int quickly overflows", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 318, | |
"OrigId": 318, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub exp {\n my ($x, $n) = @_;\n return 1 unless $n;\n return $x if $n == 1;\n return $x * exp($x*$x, ($n-1)/2) if $n%2;\n return exp($x*$x, $n/2);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 370, | |
"OrigId": 370, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "sub exp(x, n) {\n if (n===0) return 1;\n if (n===1) return x;\n return n%2 ? x * exp(x*x, (n-1)/2)\n : exp(x*x, n/2);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 429, | |
"OrigId": 429, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "jkperers37", | |
"LanguageName": "C", | |
"CodeBlock": "unsigned int exp(unsigned int x,unsigned int n)\n{\n if(n==0)\n {\n return 1;\n }\n if(n==1)\n {\n return x;\n }\n if(!(n%2))\n {\n return exp(x*x,n/2);\n }\n return x*exp(x*x,(n-1)/2);\n}", | |
"OriginalAttributionURL": "http://www.programming-idioms.org/idiom/32/integer-exponentiation-by-squaring/118/java", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-03-15T04:25:07.75492Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 430, | |
"OrigId": 430, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn exp(x: u64, n: u64) -\u003e u64 {\n match n {\n 0 =\u003e 1,\n 1 =\u003e x,\n i if i % 2 == 0 =\u003e exp(x * x, n / 2),\n _ =\u003e x * exp(x * x, (n - 1) / 2),\n } \n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2015\u0026gist=45d662e282fac50a26246047b2f717de", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2018-12-17T18:29:48.927614Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 548, | |
"OrigId": 548, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "uint exp(uint x, uint n) {\n if(n == 0)\n return 1;\n if(n == 1)\n return x;\n if(n % 2 == 0)\n return exp(x * x, n / 2);\n else\n return x * exp(x * x, (n - 1) / 2);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 635, | |
"OrigId": 635, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "int exp(int x, int n) {\n if (n == 0) return 1;\n if (n == 1) return x;\n var r = exp(x * x, n ~/ 2);\n if (n % 2 == 1) r *= x;\n return r;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/e4146e8eb23e07bfe753", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 723, | |
"OrigId": 723, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "function exp(x: integer; n: integer): integer;\n\nbegin\n if n = 0 then\n Result := 1\n else if n = 1 then\n Result := x\n else if (n and 1) = 0 then\n Result := exp(x * x, n div 2)\n else\n Result := x * exp(x * x, n div 2);\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The _integer type overflows very fast.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 726, | |
"OrigId": 726, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "int exp(int x, int n) {\n var r = 1;\n while (true) {\n if (n.isOdd) r *= x;\n n ~/= 2;\n if (n == 0) break;\n x *= x;\n }\n return r;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The idiomatic way to do exponentiation by squaring is a loop, not a recursive function.\t\r\n\r\nThis one puts the break before the x*=x to avoid an extra unnecessary multiplication at the end.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 769, | |
"OrigId": 769, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "function exp(x: QWord; n: integer): QWord;\n\nbegin\n if n = 0 then\n Result := 1\n else if n = 1 then\n Result := x\n else if (n and 1) = 0 then\n Result := exp(x * x, n div 2)\n else\n Result := x * exp(x * x, n div 2);\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_QWord is 64-bit, it overflows less quickly than _integer.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 832, | |
"OrigId": 832, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "let exp x n = x ^ n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/src/GHC.Real.html#%5E", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 891, | |
"OrigId": 891, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def exp(x, n)\n x ** n\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 932, | |
"OrigId": 932, | |
"Author": "ventsislaf", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": ":math.pow(x, n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/40b3d2f6e7", | |
"DocumentationURL": "http://www.erlang.org/doc/man/math.html#pow-2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:27.934762Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1060, | |
"OrigId": 1060, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:27.934762Z", | |
"LastEditor": "ixixeagle", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-module (int_power).\n-export ([exp/2]).\n\nexp (X, N) -\u003e exp (X, N, 1).\n\nexp (_X, 0, Y) -\u003e Y;\nexp (X, N, Y) when N rem 2 =:= 0 -\u003e\n exp (X * X, N div 2, Y);\nexp (X, N, Y) -\u003e\n exp (X * X, N div 2, X * Y).\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.erlang.org/doc/man/math.html#pow-2", | |
"AuthorComment": "Right-to-left exponentiation by squaring. Knuth TAOCP Volume 2, 3rd edition, p 462. This cleans up Algorithm A of section 4.6.3.\r\n", | |
"Version": 5, | |
"VersionDate": "2017-07-20T18:52:41.161821Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "\t", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1329, | |
"OrigId": 1329, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T16:31:45.757417Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "function exp(x, n)\r\n return x^n\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:31:45.757417Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1499, | |
"OrigId": 1499, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:17:48.72837Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "int exp(int x, int n){\r\n if (n == 0)\r\n return 1;\r\n if (n == 1)\r\n return x;\r\n if (n % 2 == 0)\r\n return exp(x * x, n / 2);\r\n else\r\n return x * exp(x * x, (n - 1) / 2);\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:17:48.72837Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1534, | |
"OrigId": 1534, | |
"Author": "nvius", | |
"CreationDate": "2016-02-18T15:45:59.262633Z", | |
"LastEditor": "nvius", | |
"LanguageName": "PHP", | |
"CodeBlock": "function custom_exp($x, $n)\r\n{\r\n if ($n === 0) {\r\n return 1;\r\n }\r\n\r\n if ($n === 1) {\r\n return $x;\r\n }\r\n\r\n if (!($n % 2)) {\r\n return custom_exp($x * $x, $n / 2);\r\n }\r\n\r\n return $x * custom_exp($x * $x, ($n - 1) / 2);\r\n}\r\n\r\necho custom_exp(5, 10);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/function.pow.php", | |
"AuthorComment": "A custom exp function using recursion. Note: an \"exp\" function already exists in PHP for powers of the constant 'e'. See documentation for \"pow\" function and \"**\" operator.", | |
"Version": 2, | |
"VersionDate": "2016-02-18T15:48:43.494385Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1602, | |
"OrigId": 1602, | |
"Author": "meshelton", | |
"CreationDate": "2016-03-14T14:57:30.448659Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "def exp(x: Int, n: Int): Int {\r\n if(n == 0) {\r\n 1\r\n } else if(n == 1) {\r\n x\r\n } else if(n%2 == 0) {\r\n exp(x*x, n/2)\r\n } else {\r\n x * exp(x*x, (n-1)/2)\r\n }\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This isn't tail recursive because of the last else branch. ", | |
"Version": 1, | |
"VersionDate": "2016-03-14T14:57:30.448659Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2456, | |
"OrigId": 2456, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T14:17:57.555916Z", | |
"LastEditor": "devbg", | |
"LanguageName": "JS", | |
"CodeBlock": "const exp = Math.pow;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-11-09T14:17:57.555916Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2460, | |
"OrigId": 2460, | |
"Author": "steenslag", | |
"CreationDate": "2018-11-18T17:10:31.569719Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def exp(x, n)\n return 1 if n == 0\n return x if n == 1\n return exp(x*x, n/2) if n.even?\n x * exp(x*x, (n-1)/2)\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-11-18T17:10:31.569719Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2760, | |
"OrigId": 2760, | |
"Author": "g19fanatic", | |
"CreationDate": "2019-09-26T14:47:10.608275Z", | |
"LastEditor": "g19fanatic", | |
"LanguageName": "Cpp", | |
"CodeBlock": "int pow(int x, int p)\n{\n if (p == 0) return 1;\n if (p == 1) return x;\n\n int tmp = pow(x, p/2);\n if (p%2 == 0) return tmp * tmp;\n else return x * tmp * tmp;\n}", | |
"OriginalAttributionURL": "https://stackoverflow.com/a/1505791/496405", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T14:47:10.608275Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2927, | |
"OrigId": 2927, | |
"Author": "joshjje", | |
"CreationDate": "2019-09-26T17:07:04.07749Z", | |
"LastEditor": "joshjje", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Math.Pow(x, n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:07:04.07749Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2946, | |
"OrigId": 2946, | |
"Author": "el_memorioso", | |
"CreationDate": "2019-09-26T17:23:16.770324Z", | |
"LastEditor": "el_memorioso", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(defn exp [x n]\n (let [x-squared (* x x)]\n (cond\n (= n 0) 1\n (= n 1) x\n (= (mod n 2) 0) (exp x-squared (/ n 2))\n :else (* x (exp x-squared (/ (- n 1) 2))))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:23:16.770324Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3137, | |
"OrigId": 3137, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T22:34:17.506618Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "fun exp(x: Int, n: Int): Int = when {\n n == 0 -\u003e 1\n n == 1 -\u003e x\n n % 2 == 0 -\u003e exp(x * x, n / 2)\n else -\u003e x * exp(x * x, (n - 1) / 2)\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:34:17.506618Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3213, | |
"OrigId": 3213, | |
"Author": "jupiter", | |
"CreationDate": "2019-09-27T09:18:16.702951Z", | |
"LastEditor": "jupiter", | |
"LanguageName": "Fortran", | |
"CodeBlock": "function exp(x,n) result(I)\nI=x**n\nend function exp", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T09:18:16.702951Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 27, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 33, | |
"OrigId": 0, | |
"Title": "Atomically read and update variable", | |
"LeadParagraph": "Assign variable _x the new value _f(_x), making sure that no other thread may modify _x between the read and the write. ", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Cpp] Unclear on the problem.", | |
"LastEditedImplID": 3376, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 27, | |
"VersionDate": "2019-09-27T23:36:48.926925Z", | |
"Implementations": [ | |
{ | |
"Id": 138, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "synchronized(lock){\n x = f(x);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "With this idiom, you have to manually ensure that any thread modifying _x is guarded by the same _lock object.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 353, | |
"OrigId": 353, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $x :shared;\n$x = 0;\n\nsub my_task {\n my $id = shift;\n for (1 .. 5) {\n sleep 2*rand();\n { # lock scope\n lock($x);\n print \"thread $id found $x\\n\";\n $x = $id;\n sleep 2*rand();\n }\n }\n}\n\nthreads-\u003ecreate('my_task', $_) for 1 .. 3;\nsleep 5 while threads-\u003elist(threads::running);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_lock is lexically scoped. Delay outside the lock scope allows other threads a chance at changing _$x.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use threads;\r\nuse threads::shared;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 497, | |
"OrigId": 497, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let mut x = x.lock().unwrap();\n*x = f(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?code=use%20std%3A%3Async%3A%3AMutex%3B%0A%0Afn%20f(x%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20x%20%2B%201%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%20Mutex%3A%3Anew(0)%3B%0A%20%20%20%20let%20mut%20x%20%3D%20x.lock().unwrap()%3B%0A%20%20%20%20*x%20%3D%20f(*x)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20*x)%3B%0A%7D%0A\u0026version=stable", | |
"DocumentationURL": "http://doc.rust-lang.org/std/sync/struct.Mutex.html#examples", | |
"AuthorComment": "Assuming _x is created like this:\r\n`let x = Mutex::new(0);`", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 569, | |
"OrigId": 569, | |
"Author": "JackStouffer", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "synchronized x = f(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The synchronized statement can also be written with braces, but for one liners, they can be omitted. \r\n\r\nThe synchronized statement automatically wraps what ever is in it in a mutex.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 883, | |
"OrigId": 883, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x = Atomic.new(0)\nx.update { |x| f(x) }", | |
"OriginalAttributionURL": "https://github.com/ruby-concurrency/atomic", | |
"DemoURL": "", | |
"DocumentationURL": "https://github.com/ruby-concurrency/atomic", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "require 'atomic'", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 994, | |
"OrigId": 994, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "putMVar x . f =\u003c\u003c takeMVar x\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Control-Concurrent-MVar.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Control.Concurrent.MVar", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1050, | |
"OrigId": 1050, | |
"Author": "LRHN", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "x = f(x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Dart is single-threaded. Other threads run in separate isolates.\r\n", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1171, | |
"OrigId": 1171, | |
"Author": "lck", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "var lock sync.RWMutex\n\nlock.Lock()\nx = f(x)\nlock.Unlock()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/f5URkHrCqu", | |
"DocumentationURL": "https://golang.org/pkg/sync/", | |
"AuthorComment": "You need to lock whenever accessing _x.", | |
"Version": 2, | |
"VersionDate": "2017-05-27T12:03:21.843497Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"sync\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1420, | |
"OrigId": 1420, | |
"Author": "TinyFawks", | |
"CreationDate": "2016-02-18T16:57:58.598676Z", | |
"LastEditor": "TinyFawks", | |
"LanguageName": "Python", | |
"CodeBlock": "lock = threading.Lock()\n\nlock.acquire()\ntry:\n\tx = f(x)\nfinally:\n\tlock.release()", | |
"OriginalAttributionURL": "http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/2/library/threading.html#lock-objects", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.598676Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import threading", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1608, | |
"OrigId": 1608, | |
"Author": "JPSII", | |
"CreationDate": "2016-03-20T23:33:01.124565Z", | |
"LastEditor": "JPSII", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var\r\n loc: TCriticalSection;\r\nbegin\r\n loc.Enter;\r\n try\r\n x := f(x);\r\n finally\r\n loc.Leave;\r\n end;\r\nend.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-03-20T23:33:23.838943Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses syncobjs;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1625, | |
"OrigId": 1625, | |
"Author": "AgillaDev", | |
"CreationDate": "2016-03-29T13:42:52.389031Z", | |
"LastEditor": "AgillaDev", | |
"LanguageName": "PHP", | |
"CodeBlock": "$mutex = Mutex::create();\r\nMutex::lock($mutex);\r\n$x = f($x);\r\nMutex::unlock($mutex);\r\nMutex::destroy($mutex);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/class.mutex.php", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-03-29T13:42:52.389031Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2549, | |
"OrigId": 2549, | |
"Author": "1.7.4", | |
"CreationDate": "2019-01-24T10:57:30.474479Z", | |
"LastEditor": "1.7.4", | |
"LanguageName": "JS", | |
"CodeBlock": "let x = f(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "JavaScript is single threaded, so we can be sure that no other thread will modify x in between :3", | |
"Version": 1, | |
"VersionDate": "2019-01-24T10:57:30.474479Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3339, | |
"OrigId": 3339, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T22:35:41.361846Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "x = f(x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This is for a normal variable. In Fortran, normal variables which are not coarrays cannot be changed by another image.", | |
"Version": 1, | |
"VersionDate": "2019-09-27T22:35:41.361846Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3341, | |
"OrigId": 3341, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T22:38:10.071704Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "integer, dimension[*] :: x\n\ncritical\n x = f(x)\nend critical", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This is for a coarray scalar variable, which could be changed by another image.", | |
"Version": 1, | |
"VersionDate": "2019-09-27T22:38:10.071704Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3376, | |
"OrigId": 3376, | |
"Author": "chardan", | |
"CreationDate": "2019-09-27T23:34:09.445394Z", | |
"LastEditor": "chardan", | |
"LanguageName": "Cpp", | |
"CodeBlock": "atomic_int i = 1;\n\ni = 5;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "I'm a bit unclear on whether the example is asking for an atomic value or something projected with a lock; I've shown an atomic.", | |
"Version": 2, | |
"VersionDate": "2019-09-27T23:36:48.923208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 15, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 34, | |
"OrigId": 0, | |
"Title": "Create a Set of objects", | |
"LeadParagraph": "Declare and initialize a Set _x containing objects of type _T.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Perl implementation by user [daxim]", | |
"LastEditedImplID": 3224, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 28, | |
"VersionDate": "2019-09-27T10:29:13.833704Z", | |
"Implementations": [ | |
{ | |
"Id": 139, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "Set\u003cT\u003e x = new HashSet\u003cT\u003e();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html", | |
"AuthorComment": "The type _T must respect the equals() / hashcode() contract.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Set;\r\nimport java.util.HashSet;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 140, | |
"OrigId": 140, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "x := make(map[T]bool)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/yJ3PjYwXYn", | |
"DocumentationURL": "", | |
"AuthorComment": "There is no built-in Set type, but you can create a Map with key type _T and boolean value (which will be ignored).", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 408, | |
"OrigId": 408, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "let x: HashSet\u003cT\u003e = HashSet::new();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?code=use%20std%3A%3Acollections%3A%3AHashSet%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20mut%20m%20%3D%20HashSet%3A%3Anew()%3B%0A%20%20%20%20m.insert(%22a%22)%3B%0A%20%20%20%20m.insert(%22b%22)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20m)%3B%0A%7D\u0026version=stable", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::collections::HashSet;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 625, | |
"OrigId": 625, | |
"Author": "JackStouffer", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "nickname", | |
"LanguageName": "Python", | |
"CodeBlock": "class T(object):\n pass\n\nx = set(T())", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 650, | |
"OrigId": 650, | |
"Author": "cym13", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "auto x = redBlackTree!T;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://dlang.org/phobos/std_container_rbtree.html", | |
"AuthorComment": "By default standard red-black trees don't accept duplicates, hence making great sets.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.container: redBlackTree;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 746, | |
"OrigId": 746, | |
"Author": "LRHN", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "var x = new Set\u003cT\u003e();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 857, | |
"OrigId": 857, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "x = Set.new", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/stdlib-2.2.3/libdoc/set/rdoc/Set.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "require 'set'", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 973, | |
"OrigId": 973, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "x = empty :: Set T\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/containers/docs/Data-Set.html#v:empty", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Data.Set", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1014, | |
"OrigId": 1014, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.646023Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "x := make(map[T]struct{})", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/1m1WukwSv_", | |
"DocumentationURL": "", | |
"AuthorComment": "The struct{} type is space efficient because it occupies zero bytes in memory.\r\nBut it is less intuitive to use than a bool value.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.646023Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2457, | |
"OrigId": 2457, | |
"Author": "devbg", | |
"CreationDate": "2018-11-09T14:23:13.236294Z", | |
"LastEditor": "devbg", | |
"LanguageName": "JS", | |
"CodeBlock": "class T {}\nlet x = new Set([new T]);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-11-09T14:23:13.236294Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2595, | |
"OrigId": 2595, | |
"Author": "Debaran", | |
"CreationDate": "2019-02-02T03:12:29.823582Z", | |
"LastEditor": "Debaran", | |
"LanguageName": "Scala", | |
"CodeBlock": "val x = Set[T]()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The default implementation of _Set is a _HashSet", | |
"Version": 2, | |
"VersionDate": "2019-02-02T03:13:47.523019Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2806, | |
"OrigId": 2806, | |
"Author": "aolszowka", | |
"CreationDate": "2019-09-26T15:25:11.778021Z", | |
"LastEditor": "aolszowka", | |
"LanguageName": "Csharp", | |
"CodeBlock": "HashSet\u003cT\u003e x = new HashSet\u003cT\u003e();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1?view=netframework-4.8", | |
"AuthorComment": "Where T is the type of element", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:25:11.778021Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System.Collections.Generic;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3224, | |
"OrigId": 3224, | |
"Author": "daxim", | |
"CreationDate": "2019-09-27T10:29:13.830937Z", | |
"LastEditor": "daxim", | |
"LanguageName": "Perl", | |
"CodeBlock": "class T {}\nclass Set::Object::T extends Set::Object {\n method BUILDARGS(T @items) { return {data =\u003e \\@items}; }\n method insert(T @items) { $self-\u003enext::method(@items); }\n}\nmy $x = Set::Object::T-\u003enew(T-\u003enew, T-\u003enew, T-\u003enew);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T10:29:13.830937Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use Moops;\r\nuse Set::Object qw();\r\n", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 13, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
40, | |
118 | |
], | |
"RelatedIdiomTitles": [ | |
"Graph with adjacency lists", | |
"List to set" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 35, | |
"OrigId": 0, | |
"Title": "First-class function : compose", | |
"LeadParagraph": "Implement a function _compose (_A -\u003e _C) with parameters _f (_A -\u003e _B) and _g (_B -\u003e _C), which returns composition function _g ∘ _f", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Clojure implementation by user [saighdear]", | |
"LastEditedImplID": 3288, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 42, | |
"VersionDate": "2019-09-27T17:09:20.900279Z", | |
"Implementations": [ | |
{ | |
"Id": 141, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func compose(f func(A) B, g func(B) C) func(A) C {\n\treturn func(x A) C {\n\t\treturn g(f(x))\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/CgWPoW48_h", | |
"DocumentationURL": "", | |
"AuthorComment": "Functions are first-class citizens in Go. They are passed as arguments and as return values.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 142, | |
"OrigId": 142, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "function compose(f,g){\n return function(x){\n return g(f(x));\n };\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://jsfiddle.net/JWhL5/", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 325, | |
"OrigId": 325, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub compose {\n my ($f, $g) = @_;\n return sub {\n return $g-\u003e($f-\u003e(shift))\n }\n}\n\nsub double { return 2*shift }\nsub triple { return 3*shift }\nsub aFunc = compose(\\\u0026double, \\\u0026triple);\naFunc-\u003e(7);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "To pass a function reference to a function, you need the \\\u0026 operator. To call a function reference, you need to use -\u003e.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 442, | |
"OrigId": 442, | |
"Author": "Flyingmana", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function compose($f, $g)\n{\n return function ($x) use ($f, $g) {\n return $g($f($x));\n };\n};", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:21:53.927073Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 568, | |
"OrigId": 568, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "auto compose(f, g) {\n\treturn std.functional.compose!(f, g);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.functional;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 585, | |
"OrigId": 585, | |
"Author": "Stebalien", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn compose\u003c'a, A, B, C, G, F\u003e(f: F, g: G) -\u003e Box\u003cFn(A) -\u003e C + 'a\u003e\n\twhere F: 'a + Fn(A) -\u003e B, G: 'a + Fn(B) -\u003e C\n{\n\tBox::new(move |x| g(f(x)))\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Unfortunately, you'll need to implement another two variants if you care about `FnMut` and `FnOnce`. Also, for now, you need to box the returned function. In the future, this shouldn't be necessary.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 667, | |
"OrigId": 667, | |
"Author": "cym13", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "cym13", | |
"LanguageName": "Python", | |
"CodeBlock": "def compose(f, g):\n return lambda a: g(f(a))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "We could have used a named function but a lambda is shorter", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 730, | |
"OrigId": 730, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "typedef R Func\u003cT,R\u003e(T arg);\n\nFunc\u003cA,C\u003e compose(B f(A x), C g(B x)) =\u003e (A x) =\u003e g(f(x))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Function types can be written directly on parameters, but not in the return type, so it needs a typedef to declare the types of this function.\r\n\r\nWithout the types it's just:\r\n compose(f,g)=\u003e(x)=\u003eg(f(x));\r\n", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 780, | |
"OrigId": 780, | |
"Author": "nsmryan", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "compose :: (A -\u003e B) -\u003e (B -\u003e C) -\u003e A -\u003e C\ncompose = flip (.)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Function composition is performed by the function \".\". The parenthesis in the implementation are because the function is an operator and is usually infix.\r\n\r\nThe function _flip swaps the order of the arguments to the function it is applied to, since the compose function has type signature (B -\u003e C) -\u003e (A -\u003e B) -\u003e A -\u003e C.\r\n\r\nThe type signature (the first line) is optional and could be omitted.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 781, | |
"OrigId": 781, | |
"Author": "nsmryan", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "compose :: (A -\u003e B) -\u003e (B -\u003e C) -\u003e A -\u003e C\ncompose f g x = g (f x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The type signature (the first line) is optional and could be omitted.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.120844Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 879, | |
"OrigId": 879, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:28.120844Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def compose(f, g)\r\n -\u003e x { g.(f.(x)) }\r\nend\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWsO/0", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-13T22:59:57.151329Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1512, | |
"OrigId": 1512, | |
"Author": "openCage", | |
"CreationDate": "2016-02-17T15:43:23.96879Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "public \u003cA,B,C\u003e Function\u003cA,C\u003e compose(Function\u003cA,B\u003e f, Function\u003cB,C\u003e g){\r\n return x -\u003e g.apply(f.apply(x));\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-02-17T16:06:11.313186Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1666, | |
"OrigId": 1666, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T07:58:43.06179Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "function compose(f,g)\r\n return function(x)\r\n return g(f(x))\r\n end\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/rWl7cZNq", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-07T07:58:43.06179Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1756, | |
"OrigId": 1756, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-07-12T21:23:24.009247Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-spec compose(fun((A) -\u003e B), fun((B) -\u003e C)) -\u003e fun((A) -\u003e C).\r\ncompose(F, G) -\u003e fun(X) -\u003e G(F(X)) end.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-07-12T21:23:24.009247Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2027, | |
"OrigId": 2027, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-12T15:43:36.416694Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (compose f g)\n (lambda (x) (g (f (x)))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-12T15:43:36.416694Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2474, | |
"OrigId": 2474, | |
"Author": "freecoder", | |
"CreationDate": "2018-12-17T19:42:03.97462Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn compose\u003cA, B, C\u003e(f: impl Fn(A) -\u003e B, g: impl Fn(B) -\u003e C) -\u003e impl Fn(A) -\u003e C {\n move |x| g(f(x))\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2018\u0026gist=3ef3cc7c1ce5ac1bc29119396582b123", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-12-17T19:42:03.97462Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2815, | |
"OrigId": 2815, | |
"Author": "er2", | |
"CreationDate": "2019-09-26T15:36:24.097617Z", | |
"LastEditor": "er2", | |
"LanguageName": "Java", | |
"CodeBlock": "Function\u003cInteger, Integer\u003e addOne = i-\u003e i + 1;\nFunction\u003cInteger, String\u003e toString = i-\u003e i.toString();\nFunction\u003cInteger, String\u003e printIncremented = toString.compose(addOne);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html#compose-java.util.function.Function-", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:36:24.097617Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.function.Function;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2903, | |
"OrigId": 2903, | |
"Author": "droud", | |
"CreationDate": "2019-09-26T16:52:28.419505Z", | |
"LastEditor": "droud", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Func\u003cA, C\u003e compose\u003cA, B, C\u003e(Func\u003cA, B\u003e g, Func\u003cB, C\u003e f) =\u003e (A a) =\u003e f(g(a));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Lambda syntax.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:03:40.341631Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3049, | |
"OrigId": 3049, | |
"Author": "narrowtux", | |
"CreationDate": "2019-09-26T19:44:28.209514Z", | |
"LastEditor": "narrowtux", | |
"LanguageName": "Elixir", | |
"CodeBlock": "def compose(f, g) do\n fn a -\u003e\n g.(f.(a))\n end\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:44:28.209514Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3243, | |
"OrigId": 3243, | |
"Author": "arouene", | |
"CreationDate": "2019-09-27T11:40:16.849463Z", | |
"LastEditor": "arouene", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::function\u003cC (A)\u003e compose(B (\u0026f)(A), C (\u0026g)(B))\n{\n return [\u0026f, \u0026g](A a){return g(f(a));};\n}\n\nauto fn = compose(f, g);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://cpp.sh/9p3kh", | |
"DocumentationURL": "", | |
"AuthorComment": "using lambda", | |
"Version": 1, | |
"VersionDate": "2019-09-27T11:40:16.849463Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cfunctional\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3288, | |
"OrigId": 3288, | |
"Author": "saighdear", | |
"CreationDate": "2019-09-27T17:09:20.897119Z", | |
"LastEditor": "saighdear", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(defn compose [f g]\n (comp g f))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojuredocs.org/clojure.core/comp", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T17:09:20.897119Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 21, | |
"Rating": 1, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
36 | |
], | |
"RelatedIdiomTitles": [ | |
"First-class function : generic composition" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 36, | |
"OrigId": 0, | |
"Title": "First-class function : generic composition", | |
"LeadParagraph": "Implement a function _compose which returns composition function _g ∘ _f for any functions _f and _g having exactly 1 parameter.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Java implementation by user [jezza]", | |
"LastEditedImplID": 3405, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 24, | |
"VersionDate": "2019-09-28T03:20:54.747739Z", | |
"Implementations": [ | |
{ | |
"Id": 143, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "function compose(f,g){\n return function(x){\n return g(f(x));\n };\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/CgWPoW48_h", | |
"DocumentationURL": "", | |
"AuthorComment": "In Javascript this is valid regardless the type of the inputs and outputs.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 250, | |
"OrigId": 250, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define (compose f g) \n\t(lambda x \n\t\t(f (apply g x))))", | |
"OriginalAttributionURL": "http://stackoverflow.com/q/1693181/871134", | |
"DemoURL": "http://repl.it/7TZ", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 345, | |
"OrigId": 345, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub compose {\n my ($f, $g) = @_;\n return sub {\n my $x = shift;\n return $g-\u003e($f-\u003e($x));\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 586, | |
"OrigId": 586, | |
"Author": "Stebalien", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "Stebalien", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn compose\u003c'a, A, B, C, G, F\u003e(f: F, g: G) -\u003e Box\u003cFn(A) -\u003e C + 'a\u003e\n\twhere F: 'a + Fn(A) -\u003e B, G: 'a + Fn(B) -\u003e C\n{\n\tBox::new(move |x| g(f(x)))\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Unfortunately, you'll need to implement another two variants if you care about `FnMut` and `FnOnce`. Also, for now, you need to box the returned function. In the future, this shouldn't be necessary.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 594, | |
"OrigId": 594, | |
"Author": "opisano", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "opisano", | |
"LanguageName": "D", | |
"CodeBlock": "auto _compose(T)(T function(T) f, T function(T) g)\n{\n auto lambda = (T x) { return g(f(x)); };\n return lambda;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 670, | |
"OrigId": 670, | |
"Author": "cym13", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "cym13", | |
"LanguageName": "Python", | |
"CodeBlock": "def compose(f, g):\n\treturn lambda x: g(f(x))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This is the same as for non-generic composition", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 741, | |
"OrigId": 741, | |
"Author": "LRHN", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "compose(f, g) =\u003e (x) =\u003e g(f(x));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 871, | |
"OrigId": 871, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def compose(f, g)\n -\u003e x { g.(f.(x)) }\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 974, | |
"OrigId": 974, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "compose f g = g . f\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Data-Function.html#v:-46-", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1187, | |
"OrigId": 1187, | |
"Author": "mem", | |
"CreationDate": "2016-02-18T16:57:58.963839Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "func composeIntFuncs(f func(int) int, g func(int) int) func(int) int {\n\treturn func(x int) int {\n\t\treturn g(f(x))\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/fxcOMi9S6t", | |
"DocumentationURL": "", | |
"AuthorComment": "Go doesn't have support for generics so the functions must take and return concrete types.\r\n\r\nIt could be done with an empty interface, but that would discard static type checks (the implementations of _f and _g can still be type-checked, though).", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:58.963839Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1623, | |
"OrigId": 1623, | |
"Author": "Feifan", | |
"CreationDate": "2016-03-29T12:47:39.668942Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "function compose($f,$g){\r\n\treturn function($x) use($f,$g) {\r\n\t\treturn $g($f($x));\r\n\t}\r\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/1609998/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-03-30T12:08:50.811625Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1664, | |
"OrigId": 1664, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T07:52:29.16428Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "function compose(f,g)\r\n return function(x)\r\n return g(f(x))\r\n end\r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/rWl7cZNq", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-07T07:52:29.16428Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1716, | |
"OrigId": 1716, | |
"Author": "AllanDeutsch", | |
"CreationDate": "2016-05-12T22:49:54.865592Z", | |
"LastEditor": "AllanDeutsch", | |
"LanguageName": "Cpp", | |
"CodeBlock": "template\u003ctypename Pred1, typename Pred2\u003e\r\nauto compose(Pred1 f, Pred2 g){\r\n return [f,g](auto x){ return g(f(x)); };\t\r\n}", | |
"OriginalAttributionURL": "https://gist.github.com/Masstronaut/c37b4370d61e03a88cc755197e15f09c", | |
"DemoURL": "https://gist.github.com/Masstronaut/c37b4370d61e03a88cc755197e15f09c", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-05-12T22:49:54.865592Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1755, | |
"OrigId": 1755, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-07-12T21:21:35.56111Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "-spec compose(fun((X) -\u003e Y), fun((Y) -\u003e Z)) -\u003e fun((X) -\u003e Z).\r\ncompose(F, G) -\u003e fun(X) -\u003e G(F(X)) end.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-07-12T21:21:35.56111Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2475, | |
"OrigId": 2475, | |
"Author": "freecoder", | |
"CreationDate": "2018-12-18T15:38:59.111052Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn compose\u003cA, B, C\u003e(f: impl Fn(A) -\u003e B, g: impl Fn(B) -\u003e C) -\u003e impl Fn(A) -\u003e C {\n move |x| g(f(x))\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2018\u0026gist=3ef3cc7c1ce5ac1bc29119396582b123", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-12-18T15:38:59.111052Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3090, | |
"OrigId": 3090, | |
"Author": "alsi", | |
"CreationDate": "2019-09-26T20:42:24.77133Z", | |
"LastEditor": "alsi", | |
"LanguageName": "JS", | |
"CodeBlock": "const compose = f =\u003e g =\u003e x =\u003e g(f(x));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Curried function is idiomatic in a functional style.\r\n\r\nRelies on ES2015 language features (lambda functions)", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:42:24.77133Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3097, | |
"OrigId": 3097, | |
"Author": "Mike N", | |
"CreationDate": "2019-09-26T20:59:35.612268Z", | |
"LastEditor": "Mike N", | |
"LanguageName": "Ruby", | |
"CodeBlock": "def compose(f, g)\n f \u003e\u003e g\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://ruby-doc.org/core-2.6/Proc.html#method-i-3E-3E", | |
"AuthorComment": "Needs Ruby \u003e= 2.6", | |
"Version": 2, | |
"VersionDate": "2019-09-26T21:01:36.295038Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3132, | |
"OrigId": 3132, | |
"Author": "ssippe", | |
"CreationDate": "2019-09-26T22:16:27.599312Z", | |
"LastEditor": "ssippe", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Func\u003cT1, T3\u003e Compose\u003cT1, T2, T3\u003e(Func\u003cT1, T2\u003e f, Func\u003cT2, T3\u003e g) =\u003e x =\u003e g(f(x));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:16:27.599312Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3405, | |
"OrigId": 3405, | |
"Author": "jezza", | |
"CreationDate": "2019-09-28T03:20:54.743954Z", | |
"LastEditor": "jezza", | |
"LanguageName": "Java", | |
"CodeBlock": " default \u003cV\u003e Function\u003cV, R\u003e compose(Function\u003c? super V, ? extends T\u003e before) {\n Objects.requireNonNull(before);\n return (V v) -\u003e apply(before.apply(v));\n }\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This is the implementation of the compose method in java.util.function.Function", | |
"Version": 1, | |
"VersionDate": "2019-09-28T03:20:54.743954Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 19, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
35 | |
], | |
"RelatedIdiomTitles": [ | |
"First-class function : compose" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 37, | |
"OrigId": 0, | |
"Title": "Currying", | |
"LeadParagraph": "Transform a function that takes multiple arguments into a function for which some of the arguments are preset.", | |
"ExtraKeywords": "curry", | |
"Author": "Adrian", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Cpp implementation by user [arouene]", | |
"LastEditedImplID": 3205, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 45, | |
"VersionDate": "2019-09-27T08:48:11.494971Z", | |
"Implementations": [ | |
{ | |
"Id": 144, | |
"OrigId": -1, | |
"Author": "Adrian", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "Adrian", | |
"LanguageName": "JS", | |
"CodeBlock": "function curry (fn, scope) {\n \n scope = scope || window;\n \n // omit curry function first arguments fn and scope\n var args = Array.prototype.slice.call(arguments, 2);\n \n return function() {\n\tvar trueArgs = args.concat(Array.prototype.slice.call(arguments, 0));\n fn.apply(scope, trueArgs);\n };\n}", | |
"OriginalAttributionURL": "http://www.dustindiaz.com/javascript-curry/", | |
"DemoURL": "http://jsfiddle.net/adriangonzy/9SW9p/1/", | |
"DocumentationURL": "", | |
"AuthorComment": "Call curry on a function, a scope and then just enumerate the arguments you want to be curried in the returned function ;)", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.255934Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 222, | |
"OrigId": 222, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "type PayFactory func(Company, *Employee, *Employee) Payroll\n\ntype CustomPayFactory func(*Employee) Payroll\n\nfunc CurryPayFactory(pf PayFactory,company Company, boss *Employee) CustomPayFactory {\n\treturn func(e *Employee) Payroll {\n\t\treturn pf(\"Richissim\", boss, e)\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/GcPcjVgiU-", | |
"DocumentationURL": "", | |
"AuthorComment": "The currying function is not generic, it must be written for each type of currying needed.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.255934Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 326, | |
"OrigId": 326, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sub curry {\n my ($func, $fixed_arg) = @_;\n return sub {\n $func-\u003e($fixed_arg, @_);\n }\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.255934Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 562, | |
"OrigId": 562, | |
"Author": "Meta", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "fdzz", | |
"LanguageName": "D", | |
"CodeBlock": "int add(int n1, int n2)\r\n{\r\n return n1 + n2;\r\n}\r\n\r\nalias add5 = curry!(add, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://dpaste.dzfl.pl/6cceb5d75a7c", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-03-21T17:01:50.850364Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.functional;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 671, | |
"OrigId": 671, | |
"Author": "cym13", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "do", | |
"LanguageName": "Python", | |
"CodeBlock": "def f(a):\n\tdef add(b):\n\t\treturn a+b\n\treturn add\n\nprint (f(2)(1))\n\n#add_to_two = partial(f, 2)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/3/library/functools.html#functools.partial", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2019-09-26T16:59:21.413984Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "from functools import partial", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 745, | |
"OrigId": 745, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "LRHN", | |
"LanguageName": "Dart", | |
"CodeBlock": "curry(f(a, b), a) =\u003e (b) =\u003e f(a, b);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Simple currying of binary funtion.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.255934Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "\t", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 870, | |
"OrigId": 870, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "adder = -\u003e a, b { a + b }\r\nadd_two = adder.curry.(2)\r\nadd_two.(5) # =\u003e 7", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWs6/0", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-13T23:10:20.488584Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 978, | |
"OrigId": 978, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:28.255934Z", | |
"LastEditor": "hrschueler", | |
"LanguageName": "Haskell", | |
"CodeBlock": "curry range\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Prelude.html#v:curry", | |
"AuthorComment": "range(a,b) = [a..b]\r\n(curry range 1) = \\ i -\u003e [1..i]\r\ncurry range :: a -\u003e a -\u003e [a]\r\ncurry :: ((a, b) -\u003e c) -\u003e a -\u003e b -\u003e c\r\n\"::\" means \"is of type\"\r\n\r\nHaskell begins with most functions already curried and allowing partial projection, hence the uncurried _range sprang to mind as a notable exception for this illustration.\r\n\r\nData.Ix contains _range", | |
"Version": 4, | |
"VersionDate": "2018-05-15T18:35:35.145549Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import Data.Ix", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1485, | |
"OrigId": 1485, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T10:15:42.499989Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Java", | |
"CodeBlock": "IntBinaryOperator simpleAdd = (a, b) -\u003e a + b;\r\nIntFunction\u003cIntUnaryOperator\u003e curriedAdd = a -\u003e b -\u003e a + b;\r\nSystem.out.println(simpleAdd.applyAsInt(4, 5));\r\nSystem.out.println(curriedAdd.apply(4).applyAsInt(5));", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/6134278/does-java-support-currying/14750362#14750362", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T10:15:42.499989Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.function.*;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1663, | |
"OrigId": 1663, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T07:40:28.30205Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "function curry2(f)\r\n return function(a)\r\n return function(b)\r\n return f(a,b)\r\n end\r\n end\r\nend\r\n\r\nfunction add(a,b)\r\n return a + b\r\nend\r\n\r\nlocal curryAdd = curry2(add)\r\nlocal add2 = curryAdd(2)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/ehx2wgVf", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-07T07:40:28.30205Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1799, | |
"OrigId": 1799, | |
"Author": "barroco", | |
"CreationDate": "2016-08-23T11:02:03.511453Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "defmodule Curry do\r\n\r\n def curry(fun) do\r\n {_, arity} = :erlang.fun_info(fun, :arity)\r\n curry(fun, arity, [])\r\n end\r\n\r\n def curry(fun, 0, arguments) do\r\n apply(fun, Enum.reverse arguments)\r\n end\r\n\r\n def curry(fun, arity, arguments) do\r\n fn arg -\u003e curry(fun, arity - 1, [arg | arguments]) end\r\n end\r\n\r\nend", | |
"OriginalAttributionURL": "http://blog.patrikstorm.com/function-currying-in-elixir", | |
"DemoURL": "http://play.elixirbyexample.com/s/15ef070434", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-02-07T22:40:35.611901Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2035, | |
"OrigId": 2035, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-14T15:17:03.163802Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "Scheme", | |
"CodeBlock": "(define add5 (curry + 5))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-06-14T15:17:03.163802Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2218, | |
"OrigId": 2218, | |
"Author": "Miquel", | |
"CreationDate": "2018-01-28T08:21:20.480956Z", | |
"LastEditor": "Miquel", | |
"LanguageName": "Rust", | |
"CodeBlock": "fn add(a: u32, b: u32) -\u003e u32 {\n a + b\n}\n\nlet add5 = move |x| add(5, x);\n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://doc.rust-lang.org/book/first-edition/closures.html", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-01-28T08:25:16.531324Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2392, | |
"OrigId": 2392, | |
"Author": "ricardo_sdl", | |
"CreationDate": "2018-08-23T01:48:53.754322Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function curry($f, ...$argsCurried)\n{\n return function (...$args) use ($f, $argsCurried) {\n $finalArgs = array_merge($argsCurried, $args);\n return call_user_func_array($f, $finalArgs);\n };\n}\n\nfunction add($n1, $n2)\n{\n return $n1 + $n2;\n}\n\n$addFive = curry('add', 5);\n\necho $addFive(2), PHP_EOL;\necho $addFive(-5), PHP_EOL;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://3v4l.org/VufKK", | |
"DocumentationURL": "https://secure.php.net/manual/en/function.call-user-func-array.php", | |
"AuthorComment": "_curry returns an anonymous function or closure (http://php.net/manual/en/functions.anonymous.php).", | |
"Version": 3, | |
"VersionDate": "2019-09-26T22:18:46.529459Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2432, | |
"OrigId": 2432, | |
"Author": "Hayley", | |
"CreationDate": "2018-09-19T00:07:19.093819Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "function curry($f, ...$argsCurried)\n{\n return function (...$args) use ($f, $argsCurried) {\n return $f(...$argsCurried, ...$args);\n };\n}\n\nfunction add($n1, $n2)\n{\n return $n1 + $n2;\n}\n\n$addFive = curry('add', 5);\n\necho $addFive(2), PHP_EOL;\necho $addFive(-5), PHP_EOL;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:17:59.032272Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2447, | |
"OrigId": 2447, | |
"Author": "schellsan", | |
"CreationDate": "2018-10-12T20:30:15.043549Z", | |
"LastEditor": "schellsan", | |
"LanguageName": "Haskell", | |
"CodeBlock": "addThem :: Num a =\u003e a -\u003e a -\u003e a\naddThem = (+)\n\nadd5 :: Num a =\u003e a -\u003e a\nadd5 = addThem 5", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-10-12T20:30:15.043549Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2605, | |
"OrigId": 2605, | |
"Author": "Debaran", | |
"CreationDate": "2019-02-02T04:24:43.669761Z", | |
"LastEditor": "Debaran", | |
"LanguageName": "Scala", | |
"CodeBlock": "def add(x: Int, y: Int) = x + y\ndef add5(n: Int) = add(5, n)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "With only single parameter list (technically not currying)", | |
"Version": 3, | |
"VersionDate": "2019-02-02T05:02:25.116217Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2606, | |
"OrigId": 2606, | |
"Author": "Debaran", | |
"CreationDate": "2019-02-02T04:27:49.913808Z", | |
"LastEditor": "Debaran", | |
"LanguageName": "Scala", | |
"CodeBlock": "def add(x: Int)(y: Int) = x + y\nval add5 = add(5)_", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "With multiple parameter lists. (_add5 takes the 1 parameter of the other parameter list)", | |
"Version": 2, | |
"VersionDate": "2019-02-02T06:14:44.35444Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2942, | |
"OrigId": 2942, | |
"Author": "droud", | |
"CreationDate": "2019-09-26T17:20:27.538182Z", | |
"LastEditor": "droud", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Func\u003cA, C\u003e curry\u003cA, B, C\u003e(Func\u003cA, B, C\u003e f, B b) =\u003e (A a) =\u003e f(a, b);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Lambda syntax.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:21:03.49568Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3035, | |
"OrigId": 3035, | |
"Author": "JG", | |
"CreationDate": "2019-09-26T19:30:01.714594Z", | |
"LastEditor": "JG", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(defun curry (fn \u0026rest args)\n (lambda (\u0026rest remaining-args)\n (apply fn (append args remaining-args))))\n\n(defun add (a b)\n (+ a b))\n\n(funcall (curry add 2) 1) \n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T19:30:01.714594Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3205, | |
"OrigId": 3205, | |
"Author": "arouene", | |
"CreationDate": "2019-09-27T08:48:11.492392Z", | |
"LastEditor": "arouene", | |
"LanguageName": "Cpp", | |
"CodeBlock": "// function taking many parameters\nint add(int a, int b)\n{\n return a + b;\n}\n\n// define a new function preseting the first parameter\nstd::function\u003cint (int)\u003e add_def(int a)\n{\n return [a](int b){return add(a, b);};\n}\n\nint result = add_def(4)(6);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://cpp.sh/6baa4", | |
"DocumentationURL": "", | |
"AuthorComment": "using closure and lambda", | |
"Version": 1, | |
"VersionDate": "2019-09-27T08:48:11.492392Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cfunctional\u003e", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 21, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 38, | |
"OrigId": 0, | |
"Title": "Extract a substring", | |
"LeadParagraph": "Find substring _t consisting in characters _i (included) to _j (excluded) of string _s.\r\n(character indexes start at 0 unless specified otherwise)", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Clojure implementation by user [saighdear]", | |
"LastEditedImplID": 3281, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/47/substring_t.png", | |
"Version": 49, | |
"VersionDate": "2019-09-27T16:30:07.118824Z", | |
"Implementations": [ | |
{ | |
"Id": 156, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "String t = s.substring(i,j);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/R8U6Pv", | |
"DocumentationURL": "", | |
"AuthorComment": "Throws _IndexOutOfBoundsException if _i is negative, or _j is larger than the length of _s, or _i is larger than _j.", | |
"Version": 2, | |
"VersionDate": "2016-10-19T21:18:34.562997Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 158, | |
"OrigId": 158, | |
"Author": "nv", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "t = s[i..j-1] ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWsV/0", | |
"DocumentationURL": "http://www.ruby-doc.org/core-2.1.1/String.html#method-i-slice", | |
"AuthorComment": "In ruby _j is included by default\r\ns = \"test\"\r\nt = \"s[0..1] =\u003e \"te\"", | |
"Version": 2, | |
"VersionDate": "2016-11-13T23:03:43.621207Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 186, | |
"OrigId": 186, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "t = s[i:j]", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/663171/is-there-a-way-to-substring-a-string-in-python/663175#663175", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Slicing works on strings.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 205, | |
"OrigId": 205, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var t = s.substring(i, j);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-core.String#id_substring", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 309, | |
"OrigId": 309, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "gdey", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $chunk = substr(\"now is the time\", $i, $j);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://perldoc.perl.org/functions/substr.html", | |
"AuthorComment": "Perl is 0-based: _i=_3 would start at the _4th character.", | |
"Version": 2, | |
"VersionDate": "2016-01-01T19:58:01.21866Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 363, | |
"OrigId": 363, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "t = s.substring(i, j);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 461, | |
"OrigId": 461, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "$t = mb_substr($s, $i, $j-$i, 'UTF-8');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Requires multibyte (mb) extension for unicode support.\r\n", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 470, | |
"OrigId": 470, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "C", | |
"CodeBlock": "char *t=malloc((j-i+1)*sizeof(char));\nstrncpy(t,s+i,j-i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e\r\n#include \u003cstring.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 537, | |
"OrigId": 537, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "auto t = s[i .. j];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 644, | |
"OrigId": 644, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "t := copy(s,i+1,j-i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 683, | |
"OrigId": 683, | |
"Author": "killercup", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "killercup", | |
"LanguageName": "Rust", | |
"CodeBlock": "let t = s.graphemes(true).skip(i).take(j - i).collect::\u003cString\u003e();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?code=extern%20crate%20unicode_segmentation%3B%0Ause%20unicode_segmentation%3A%3AUnicodeSegmentation%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20s%20%3D%20%22Lorem%20Ips%C3%BCm%20Dolor%22%3B%0A%20%20%20%20let%20(i%2C%20j)%20%3D%20(6%2C%2011)%3B%0A%20%20%20%20let%20t%20%3D%20s.graphemes(true).skip(i).take(j%20-%20i).collect%3A%3A%3CString%3E()%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20t)%3B%0A%7D%0A\u0026version=stable", | |
"DocumentationURL": "http://unicode-rs.github.io/unicode-segmentation/unicode_segmentation/trait.UnicodeSegmentation.html", | |
"AuthorComment": "Treats the 'character indexes' as indices of 'extended grapheme clusters' as defined by Unicode.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "extern crate unicode_segmentation;\r\nuse unicode_segmentation::UnicodeSegmentation;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 836, | |
"OrigId": 836, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "t = drop i (take j s)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.309182Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 986, | |
"OrigId": 986, | |
"Author": "hashd", | |
"CreationDate": "2015-11-30T12:37:28.309182Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "t = String.slice(s, i..j-1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/8fcff9b61e", | |
"DocumentationURL": "http://elixir-lang.org/docs/stable/elixir/String.html#slice/2", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T21:21:19.34619Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1133, | |
"OrigId": 1133, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T03:18:48.60278Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "T = string:sub_string(I, J-1).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Erlang uses 1-based lists", | |
"Version": 1, | |
"VersionDate": "2015-12-18T03:18:48.60278Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1179, | |
"OrigId": 1179, | |
"Author": "lck", | |
"CreationDate": "2016-01-02T00:37:57.637898Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "t := string([]rune(s)[i:j])", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/YREgL01lmW", | |
"DocumentationURL": "", | |
"AuthorComment": "convert to []_rune because some characters are two or more bytes.", | |
"Version": 2, | |
"VersionDate": "2016-11-13T23:06:48.274967Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1343, | |
"OrigId": 1343, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T17:09:36.250636Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "t = s:sub(i, j-1)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:09:36.250636Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1378, | |
"OrigId": 1378, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T18:37:04.926986Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "auto t = s.substr(i, j-i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.cplusplus.com/reference/string/string/substr/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T18:37:04.926986Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1500, | |
"OrigId": 1500, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:19:13.827694Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "var t = s.Substring(i, j);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:19:13.827694Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1513, | |
"OrigId": 1513, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-17T15:52:48.042015Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "T : String := S (I .. J - 1);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "In Ada, strings use 1-based indexing\r\n\r\nIn Ada, _J is included by default when slicing", | |
"Version": 1, | |
"VersionDate": "2016-02-17T15:52:48.042015Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2245, | |
"OrigId": 2245, | |
"Author": "Matek", | |
"CreationDate": "2018-03-10T23:49:40.735688Z", | |
"LastEditor": "Matek", | |
"LanguageName": "Pascal", | |
"CodeBlock": "t := s.Substring(i,j-i);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-03-10T23:49:40.735688Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "uses Sysutils;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2894, | |
"OrigId": 2894, | |
"Author": "Dirk", | |
"CreationDate": "2019-09-26T16:48:52.416867Z", | |
"LastEditor": "Dirk", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(setf u (subseq s i j))\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.lispworks.com/documentation/lw70/CLHS/Body/f_subseq.htm#subseq", | |
"AuthorComment": "_t is not a good choice for a variable name in Lisp, so using _u instead for the result string", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:49:58.058129Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2931, | |
"OrigId": 2931, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T17:10:03.204625Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "character(len=:), allocatable :: t\n\n t = s(i:j-1)\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "In Fortran, characters start with index one.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:10:03.204625Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3281, | |
"OrigId": 3281, | |
"Author": "saighdear", | |
"CreationDate": "2019-09-27T16:30:07.109466Z", | |
"LastEditor": "saighdear", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(def t (subs s i j))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojuredocs.org/clojure.core/subs", | |
"AuthorComment": "Uses String.substring (Java) internally", | |
"Version": 1, | |
"VersionDate": "2019-09-27T16:30:07.109466Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 23, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
39, | |
46, | |
47 | |
], | |
"RelatedIdiomTitles": [ | |
"Check if string contains a word", | |
"Extract beginning of string (prefix)", | |
"Extract string suffix" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 39, | |
"OrigId": 0, | |
"Title": "Check if string contains a word", | |
"LeadParagraph": "Set boolean _ok to _true if string _word is contained in string _s as a substring, or to _false otherwise.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [tkoenig]", | |
"LastEditedImplID": 3200, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 42, | |
"VersionDate": "2019-09-27T08:35:20.219179Z", | |
"Implementations": [ | |
{ | |
"Id": 157, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "boolean ok = s.contains(word);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://ideone.com/Mu2rdM", | |
"DocumentationURL": "https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#contains-java.lang.CharSequence-", | |
"AuthorComment": "Function String._contains() exists since java 1.5", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 206, | |
"OrigId": 206, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var ok = s.contains(word);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-core.String#id_contains", | |
"AuthorComment": "Argument of _contains must be a Pattern.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 327, | |
"OrigId": 327, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "$ok = index($s,$word) \u003e= 0;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 374, | |
"OrigId": 374, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var ok = s.indexOf(word) !== -1;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_indexOf returns -_1 if the word isn't found.", | |
"Version": 2, | |
"VersionDate": "2016-11-11T20:01:51.945741Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 397, | |
"OrigId": 397, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "ok := strings.Contains(s, word)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/NMIIHMDcYt", | |
"DocumentationURL": "http://golang.org/pkg/strings/#Contains", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"strings\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 427, | |
"OrigId": 427, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "let ok = s.contains(word);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-12-17T18:33:51.9393Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 428, | |
"OrigId": 428, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "C", | |
"CodeBlock": "int ok=strstr(s,word)!=NULL;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 431, | |
"OrigId": 431, | |
"Author": "Flyingmana", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "Flyingmana", | |
"LanguageName": "PHP", | |
"CodeBlock": "$ok = strpos($s, $word) !== false;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 540, | |
"OrigId": 540, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "bool ok = s.canFind(word);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.algorithm.searching;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 571, | |
"OrigId": 571, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "Python", | |
"CodeBlock": "ok = word in s", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 647, | |
"OrigId": 647, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "ok := pos(word,s)\u003c\u003e0;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 842, | |
"OrigId": 842, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "ok = s.include?(word)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/String.html#method-i-include-3F", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 858, | |
"OrigId": 858, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "ok = word `isInfixOf` s\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:28.369178Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 899, | |
"OrigId": 899, | |
"Author": "rrrene", | |
"CreationDate": "2015-11-30T12:37:28.369178Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "ok = String.contains?(s, word)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/8209c9f4be", | |
"DocumentationURL": "http://elixir-lang.org/docs/stable/elixir/String.html#contains?/2", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T21:32:54.140192Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1129, | |
"OrigId": 1129, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T03:10:03.025519Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "Ok = string:str(S, Word) \u003e 0.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=1bf3", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/string.html?i=0\u0026search=string:st#str/2", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-12-18T03:10:03.025519Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1347, | |
"OrigId": 1347, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T17:16:27.808281Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lua", | |
"CodeBlock": "ok = s:find(word, 1, true)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This sets _ok to the starting index of the first occurrence of _word, or _nil if there is no occurrence. These results are truey and falsey respectively.\r\n\r\nIf you need _ok to equate _true or _false, then see other implementation.", | |
"Version": 2, | |
"VersionDate": "2016-11-11T20:07:45.614343Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1502, | |
"OrigId": 1502, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:23:12.982139Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "var ok = s.Contains(word);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-11T19:59:49.454437Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1531, | |
"OrigId": 1531, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-18T08:50:40.030335Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "Ok : Boolean := Index (S, Word) \u003e 0;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T08:50:40.030335Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "with Ada.Strings.Fixed;\r\nuse Ada.Strings.Fixed;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1899, | |
"OrigId": 1899, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-11-11T20:05:17.365284Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lua", | |
"CodeBlock": "ok = false\r\nif s:find(word, 1, true) then ok = true end", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-11-11T20:05:17.365284Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1900, | |
"OrigId": 1900, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-11-11T20:16:57.159565Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lua", | |
"CodeBlock": "ok = s:find(word, 1, true) ~= nil", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This checks that the found index is _not _nil.", | |
"Version": 1, | |
"VersionDate": "2016-11-11T20:16:57.159565Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1931, | |
"OrigId": 1931, | |
"Author": "whatwhat", | |
"CreationDate": "2016-12-16T03:28:41.928254Z", | |
"LastEditor": "whatwhat", | |
"LanguageName": "Scala", | |
"CodeBlock": "val ok = s.contains(word)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-12-16T03:28:41.928254Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2038, | |
"OrigId": 2038, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-06-29T14:22:39.18812Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var ok = s.includes(word);", | |
"OriginalAttributionURL": "https://stackoverflow.com/a/1789952/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_includes was added in ECMAScript 6.", | |
"Version": 1, | |
"VersionDate": "2017-06-29T14:22:39.18812Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2042, | |
"OrigId": 2042, | |
"Author": "suresh", | |
"CreationDate": "2017-07-17T06:20:57.196483Z", | |
"LastEditor": "suresh", | |
"LanguageName": "C", | |
"CodeBlock": "int main()\n\n{\nchar str[30]=”www.cprogrammingexpert.com”;\nclrscr();\nprintf(“\\n str = %s” , str);\nprintf(“\\n strlen(str)= %d \\n”,strlen(str));\ngetch();\nreturn 0;\n}", | |
"OriginalAttributionURL": "http://cprogrammingexpert.com/c-tutorial/c-string/c-strlen/", | |
"DemoURL": "", | |
"DocumentationURL": "http://cprogrammingexpert.com/c-tutorial/c-string/c-strlen/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2017-07-17T06:20:57.196483Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include\u003cstdio.h\u003e\r\n#include\u003cconio.h\u003e\r\n#include\u003cstring.h\u003e\r\n \r\n \r\n", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2619, | |
"OrigId": 2619, | |
"Author": "hamid914", | |
"CreationDate": "2019-02-16T08:59:52.580465Z", | |
"LastEditor": "hamid914", | |
"LanguageName": "Cpp", | |
"CodeBlock": "ok = s.find(word) != std::string::npos;", | |
"OriginalAttributionURL": "https://stackoverflow.com/a/2340309/777769", | |
"DemoURL": "http://cpp.sh/8i3k", | |
"DocumentationURL": "http://www.cplusplus.com/reference/string/string/find/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-02-16T08:59:52.580465Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2621, | |
"OrigId": 2621, | |
"Author": "Alexander", | |
"CreationDate": "2019-02-16T17:44:50.404139Z", | |
"LastEditor": "Alexander", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(def ok (string/includes? word s))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojuredocs.org/clojure.string/includes_q", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-02-16T17:44:50.404139Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "(require '[clojure.string :as string])", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3138, | |
"OrigId": 3138, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T22:35:42.510469Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val ok = s.contains(word)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:35:42.510469Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3200, | |
"OrigId": 3200, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T08:35:20.215532Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "ok = index(string, word) /= 0", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T08:35:20.215532Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 27, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
38, | |
133 | |
], | |
"RelatedIdiomTitles": [ | |
"Extract a substring", | |
"Case-insensitive string contains" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 40, | |
"OrigId": 0, | |
"Title": "Graph with adjacency lists", | |
"LeadParagraph": "Declare a _Graph data structure in which each _Vertex has a collection of its neighbouring vertices. As an example, set _G to a representation of the \"bull graph\": https://en.wikipedia.org/wiki/Bull_graph", | |
"ExtraKeywords": "graph", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "bukzor", | |
"EditSummary": "New Python implementation by user [bukzor]", | |
"LastEditedImplID": 2279, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 24, | |
"VersionDate": "2018-04-08T18:52:18.113501Z", | |
"Implementations": [ | |
{ | |
"Id": 159, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "type Vertex struct{\r\n\tId int\r\n\tLabel string\r\n\tNeighbours map[*Vertex]bool\r\n}\r\n\r\ntype Graph []*Vertex", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/BfmvKkW_Dl", | |
"DocumentationURL": "", | |
"AuthorComment": "The map is used as a Set of _Vertex pointers.\r\n_Graph is a list of all the _Vertex pointers.", | |
"Version": 2, | |
"VersionDate": "2016-05-02T12:21:05.553206Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 595, | |
"OrigId": 595, | |
"Author": "vbh", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "vbh", | |
"LanguageName": "D", | |
"CodeBlock": "struct Vertex\n{\n\tfloat x, y, z;\n\tVertex* [] adjacentVertices;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.232822Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 894, | |
"OrigId": 894, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "Vertex = Struct.new(:x, :y, :z)\nGraph = Struct.new(:vertex, :neighbours)\n\nv = Vertex.new(1, 2, 3)\nneighbours = [ Vertex.new(2, 3, 4), Vertex.new(4, 5, 6) ]\ngraph = Graph.new(v, neighbours)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.232822Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1001, | |
"OrigId": 1001, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "datatype Node = Int\ndatatype Adjacencies = [ Node ]\ndatatype Graph = [ Adjacencies ]\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.232822Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1017, | |
"OrigId": 1017, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "class Graph{\n List\u003cVertex\u003e vertices;\n\n static class Vertex{\n int id;\n List\u003cVertex\u003e neighbours;\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Of course, your implementation will also include constructors, edge methods, and graph traversal methods.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.232822Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.List;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1018, | |
"OrigId": 1018, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.232822Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "class Graph{\n Set\u003cVertex\u003e vertices;\n\n static class Vertex{\n int id;\n Set\u003cVertex\u003e neighbours;\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Using _Set containers is fine when order doesn't matter.\r\nOf course, your implementation will also include constructors, edge methods, and graph traversal methods.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.232822Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.Set;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2279, | |
"OrigId": 2279, | |
"Author": "bukzor", | |
"CreationDate": "2018-04-08T18:52:18.110083Z", | |
"LastEditor": "bukzor", | |
"LanguageName": "Python", | |
"CodeBlock": "class Vertex(set): pass\nclass Graph(defaultdict):\n def __init__(self, *paths):\n self.default_factory = Vertex\n for path in paths:\n self.make_path(path)\n\n def make_path(self, labels):\n for l1, l2 in zip(labels, labels[1:]):\n self[l1].add(l2)\n self[l2].add(l1)\n\nG = Graph((0, 1, 2, 3), (1, 4, 2))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-04-08T18:52:18.110083Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "from collections import defaultdict", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 7, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
34, | |
130, | |
129 | |
], | |
"RelatedIdiomTitles": [ | |
"Create a Set of objects", | |
"Depth-first traversing in a graph", | |
"Breadth-first traversing in a graph" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 41, | |
"OrigId": 0, | |
"Title": "Reverse a string", | |
"LeadParagraph": "Create string _t containing the same characters as string _s, in reverse order.\r\nOriginal string _s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Cobol] fix", | |
"LastEditedImplID": 3309, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/41/string-reverse.png", | |
"Version": 57, | |
"VersionDate": "2019-09-27T20:51:02.76052Z", | |
"Implementations": [ | |
{ | |
"Id": 161, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "String t = new StringBuilder(s).reverse().toString();", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/7569335/reverse-a-string-in-java#answer-7569370", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_StringBuilder is available since Java 1.5", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 162, | |
"OrigId": 162, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "runes := []rune(s)\nfor i, j := 0, len(runes)-1; i \u003c j; i, j = i+1, j-1 {\n runes[i], runes[j] = runes[j], runes[i]\n}\nt := string(runes)", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/1752414/how-to-reverse-a-string-in-go#answer-10030772", | |
"DemoURL": "http://play.golang.org/p/swFXJkofzC", | |
"DocumentationURL": "", | |
"AuthorComment": "This takes care of multi-byte runes, which count as a single character.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 187, | |
"OrigId": 187, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "t = s.decode('utf8')[::-1].encode('utf8')", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/931092/reverse-a-string-in-python/931095#931095", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-01-03T23:44:30.749232Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 208, | |
"OrigId": 208, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var t = new String.fromCharCodes(s.runes.toList().reversed);", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/21613700/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This does reverse the order of the _runes, however it may handle improperly some dependant runes like diacritics.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 223, | |
"OrigId": 223, | |
"Author": "Nico", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "t = s.reverse", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://repl.it/EWd0/1", | |
"DocumentationURL": "http://ruby-doc.org/core-1.8.6/String.html#method-i-reverse-21", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-13T15:02:38.785926Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 361, | |
"OrigId": 361, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var t = s.split(\"\").reverse().join(\"\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-01-03T23:24:55.875172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 402, | |
"OrigId": 402, | |
"Author": "killercup", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let t = s.chars().rev().collect::\u003cString\u003e();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://is.gd/Jztpr6", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2018-01-03T23:59:44.562678Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 460, | |
"OrigId": 460, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "PHP", | |
"CodeBlock": "for ($i=0;$i\u003cmb_strlen($s);$i++) {\n $characters[] = mb_substr($s, $i, 1, 'UTF-8');\n}\n\n$characters = array_reverse($characters);\n$t = implode($characters);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This solution needs _mb (multibyte) extension.", | |
"Version": 2, | |
"VersionDate": "2018-01-03T23:27:18.964171Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 532, | |
"OrigId": 532, | |
"Author": "JackStouffer", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "auto t = s.retro.array;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://dpaste.dzfl.pl/b21510935840", | |
"DocumentationURL": "", | |
"AuthorComment": "Note, _t is now a dchar[], which is a utf-32 encoded string. To convert back to the type of _s, you need to call std.conv.to.", | |
"Version": 2, | |
"VersionDate": "2018-01-03T23:23:20.780061Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.range, std.array;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 685, | |
"OrigId": 685, | |
"Author": "Bart", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "Bart", | |
"LanguageName": "Pascal", | |
"CodeBlock": "Function ReverseString(const AText: string): string;\nvar\n i,j:longint;\nbegin\n setlength(result,length(atext));\n i:=1; j:=length(atext);\n while (i\u003c=j) do\n begin\n result[i]:=atext[j-i+1];\n inc(i);\n end;\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 833, | |
"OrigId": 833, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "t = reverse s :: String\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": -1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 924, | |
"OrigId": 924, | |
"Author": "ventsislaf", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "t = String.reverse(s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/9997b7b33f", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/String.html#reverse/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1128, | |
"OrigId": 1128, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "T = lists:reverse(S)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/lists.html?i=0\u0026search=lists:rever#reverse/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1381, | |
"OrigId": 1381, | |
"Author": "bdadams", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "bdadams", | |
"LanguageName": "Csharp", | |
"CodeBlock": "char[] charArray = s.ToCharArray();\nArray.Reverse(charArray);\nstring t = new string(charArray);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.271208Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1450, | |
"OrigId": 1450, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-18T16:57:59.271208Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Scala", | |
"CodeBlock": "s.reverse", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-01-04T00:00:29.509484Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1672, | |
"OrigId": 1672, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T09:20:58.111015Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Lua", | |
"CodeBlock": "function utf8.reverse(s)\n\tlocal r = \"\"\n\tfor p,c in utf8.codes(s) do\n\t\tr = utf8.char(c)..r\n\tend\n\treturn r\nend\n\nt = utf8.reverse(s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.lua.org/manual/5.3/manual.html#6.5", | |
"AuthorComment": "if string _s is an ascii string you can directly use string.reverse instead.\r\n\r\nYou will also need Lua5.3 or an utf8 module", | |
"Version": 2, | |
"VersionDate": "2018-01-03T23:26:00.950095Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2213, | |
"OrigId": 2213, | |
"Author": "Ed", | |
"CreationDate": "2018-01-17T15:41:02.466392Z", | |
"LastEditor": "Edward E.", | |
"LanguageName": "Dart", | |
"CodeBlock": "var t = s.split('').reversed.join();\n\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-01-17T15:42:12.782141Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2215, | |
"OrigId": 2215, | |
"Author": "holicron", | |
"CreationDate": "2018-01-25T09:10:54.672082Z", | |
"LastEditor": "holicron", | |
"LanguageName": "Pascal", | |
"CodeBlock": "function reverse(const str: string): string;\nvar\n i, j: Integer;\nbegin\n j := length(str);\n setlength(reverse, j);\n for i := 1 to j do\n reverse[i] := str[j - i + 1];\nend;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-01-25T09:10:54.672082Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2242, | |
"OrigId": 2242, | |
"Author": "wobray", | |
"CreationDate": "2018-03-07T03:20:06.771964Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $t = scalar reverse $s;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "**DOESN'T WORK WITH MULTI-BYTE CHARACTERS**\r\n\r\nThis snippet will be deleted soon", | |
"Version": 2, | |
"VersionDate": "2019-09-27T08:28:08.032223Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2714, | |
"OrigId": 2714, | |
"Author": "Rochelimit", | |
"CreationDate": "2019-09-26T13:57:21.819714Z", | |
"LastEditor": "Rochelimit", | |
"LanguageName": "Python", | |
"CodeBlock": "t = s[::-1]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T13:57:21.819714Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2801, | |
"OrigId": 2801, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:20:48.460284Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(reverse s)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:20:48.460284Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2830, | |
"OrigId": 2830, | |
"Author": "alok99", | |
"CreationDate": "2019-09-26T15:47:14.907618Z", | |
"LastEditor": "alok99", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::string s(\"Example\");\nstd::string t;\nstd::copy(s.crbegin(), s.crend(), std::back_inserter(t));\n", | |
"OriginalAttributionURL": "https://en.cppreference.com/w/cpp/string/basic_string/rbegin", | |
"DemoURL": "", | |
"DocumentationURL": "https://en.cppreference.com/w/cpp/string/basic_string/rbegin", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:47:48.952068Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2958, | |
"OrigId": 2958, | |
"Author": "daniel", | |
"CreationDate": "2019-09-26T17:29:39.855072Z", | |
"LastEditor": "daniel", | |
"LanguageName": "C", | |
"CodeBlock": "char *strrev(char *s)\n{\n\tsize_t len = strlen(s);\n\tchar *rev = malloc(len + 1);\n\n\tif (rev) {\n\t\tchar *p_s = s + len - 1;\n\t\tchar *p_r = rev;\n\n\t\tfor (; len \u003e 0; len--)\n\t\t\t*p_r++ = *p_s--;\n\t\t*p_r = '\\0';\n\t}\n\treturn rev;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Returns NULL on failure", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:29:39.855072Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e\r\n#include \u003cstring.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3011, | |
"OrigId": 3011, | |
"Author": "fojji", | |
"CreationDate": "2019-09-26T18:43:23.445074Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val t = s.reversed()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T08:24:19.69011Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3013, | |
"OrigId": 3013, | |
"Author": "jamesleonis", | |
"CreationDate": "2019-09-26T18:44:37.034746Z", | |
"LastEditor": "jamesleonis", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(let [s \"hello\"\n t (apply str (reverse s))]\n t)", | |
"OriginalAttributionURL": "https://clojuredocs.org/clojure.core/reverse", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojuredocs.org/clojure.core/reverse", | |
"AuthorComment": "Strings are treated as sequential collections of characters. _reverse returns the character list in reverse order, and _apply takes this collection and feeds it as arguments into _str to return a full reversed string.\r\n\r\nAs Clojure data structures are immutable, we can guarantee that _s is unaltered.", | |
"Version": 1, | |
"VersionDate": "2019-09-26T18:44:37.034746Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3206, | |
"OrigId": 3206, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T08:49:10.575313Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " character(len=:), allocatable :: string_t\n integer ::i,n\n\n allocate (string_t, mold=string_s)\n n = len(string_s)\n do i=0,n-1\n string_t(n-i:n-i) = string_s(i+1:i+1)\n end do", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T08:49:10.575313Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3309, | |
"OrigId": 3309, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-27T20:41:06.256732Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. reverse string.\nPROCEDURE DIVISION.\n MOVE FUNCTION REVERSE(s) TO t\nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T20:51:02.757602Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 27, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
19 | |
], | |
"RelatedIdiomTitles": [ | |
"Reverse a list" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 42, | |
"OrigId": 0, | |
"Title": "Continue outer loop", | |
"LeadParagraph": "Print each item _v of list _a which in not contained in list _b.\r\nFor this, write an outer loop to iterate on _a and an inner loop to iterate on _b.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [tkoenig]", | |
"LastEditedImplID": 3257, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/42/continue.png", | |
"Version": 33, | |
"VersionDate": "2019-09-27T13:43:17.749313Z", | |
"Implementations": [ | |
{ | |
"Id": 163, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "mainloop:\n\tfor _, v := range a {\n\t\tfor _, w := range b {\n\t\t\tif v == w {\n\t\t\t\tcontinue mainloop\n\t\t\t}\n\t\t}\n\t\tfmt.Println(v)\n\t}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/exTZyM5Dl8", | |
"DocumentationURL": "", | |
"AuthorComment": "_mainloop is a label used to refer to the outer loop.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 165, | |
"OrigId": 165, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "mainloop: for(int v:a){\n\tfor(int w:b){\n\t\tif(v==w)\n\t\t\tcontinue mainloop;\n\t}\n\tSystem.out.println(v);\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://ideone.com/7zcoRD", | |
"DocumentationURL": "", | |
"AuthorComment": "_mainloop is a label used to refer to the outer loop.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 344, | |
"OrigId": 344, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "OUTER:\nfor my $v (@a) {\n for my $check (@b) {\n next OUTER if $v == $check;\n }\n print \"$v not in the list\\n\";\n}\n ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 375, | |
"OrigId": 375, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "OUTER:\nfor (var i in a) {\n for (var j in b) {\n continue OUTER if a[i] === b[j];\n }\n console.log(a[i] + \" not in the list\");\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 578, | |
"OrigId": 578, | |
"Author": "dermetfan", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "dermetfan", | |
"LanguageName": "Rust", | |
"CodeBlock": "'outer: for va in \u0026a {\n for vb in \u0026b {\n if va == vb {\n continue 'outer;\n }\n }\n println!(\"{}\", va);\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?gist=f02f06e7c244558e542d\u0026version=stable", | |
"DocumentationURL": "", | |
"AuthorComment": "'outer is a label used to refer to the outer loop. Labels in Rust start with a '.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 583, | |
"OrigId": 583, | |
"Author": "Jay", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "auto a = [1,2,3,4,5];\nauto b = [3,5];\n\nvoid main()\n{\nmainloop:\n\tforeach(v; a){\n\t\tforeach(w; b){\n\t\t\tif(v == w) continue mainloop;\n\t\t}\n\t\twriteln(v);\t\t \n\t}\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://dlang.org/statement.html#ContinueStatement", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.stdio;\r\n", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 598, | |
"OrigId": 598, | |
"Author": "sigurdm", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "sigurdm", | |
"LanguageName": "Dart", | |
"CodeBlock": "main() {\n var a = [1, 2, 3];\n var b = [2, 3];\n\n outer: for (var v in a) {\n for (var w in b) {\n if (w == v) continue outer;\n }\n print(v);\n }\n}\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/?source=991975ea-bbd0-4170-a6ca-c999f92b802e", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 721, | |
"OrigId": 721, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": " for v in a do\n begin\n for w in b do\n if (v = w) then\n break;\n if (v = w) then\n Continue;\n writeln(v);\n end; ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "You have to break the inner loop first, before you can continue the outer loop.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 975, | |
"OrigId": 975, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "sequence_ [ print v | v \u003c- a, [ u | u \u003c- b, u == v] == [] ]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Data-List.html#v:-92--92-", | |
"AuthorComment": "_a _\\\\ _b abbreviates this task if you are not required to write your own printing iterations\r\n\r\nOur outer loop continues to the next element whenever the inner list equality test breaks the inner iteration lazily after the first of any [u|u==w] found growing too large to equal [].", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1264, | |
"OrigId": 1264, | |
"Author": "cym13", | |
"CreationDate": "2016-02-18T16:57:59.339267Z", | |
"LastEditor": "cym13", | |
"LanguageName": "Python", | |
"CodeBlock": "for v in a:\n try:\n for u in b:\n if v == u:\n raise Exception()\n print(v)\n except Exception:\n continue\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Note that using two loops like this in python is by itself _very un-idiomatic. Also one would be wise to define a custom exception to avoid hiding \"real\" exceptions.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.339267Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1633, | |
"OrigId": 1633, | |
"Author": "steenslag", | |
"CreationDate": "2016-04-06T19:30:20.598861Z", | |
"LastEditor": "steenslag", | |
"LanguageName": "Ruby", | |
"CodeBlock": "a.each do |v|\r\n catch :matched do\r\n b.each do |u|\r\n throw :matched if v == u\r\n end\r\n puts v\r\n end \r\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Idiomatic ruby would be: puts a-b", | |
"Version": 1, | |
"VersionDate": "2016-04-06T19:30:20.598861Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1965, | |
"OrigId": 1965, | |
"Author": "empyrical", | |
"CreationDate": "2017-04-13T12:08:50.353562Z", | |
"LastEditor": "empyrical", | |
"LanguageName": "PHP", | |
"CodeBlock": "$array_1 = [1,2,3,4,5];\r\n$array_2 = [3,4];\r\n\r\nforeach ($array_1 as $a) {\r\n foreach ($array_2 as $b) {\r\n if ($b == $a) {\r\n continue 2;\r\n }\r\n }\r\n echo $a\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/control-structures.continue.php", | |
"AuthorComment": "The number next to the _continue statement determines how many loops \"up\" it should skip. _continue _1 is the same as _continue with no numerical argument passed, and will skip to the next iteration of the current loop.", | |
"Version": 1, | |
"VersionDate": "2017-04-13T12:08:50.353562Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2009, | |
"OrigId": 2009, | |
"Author": "Dodopod", | |
"CreationDate": "2017-06-05T15:53:59.713578Z", | |
"LastEditor": "Dodopod", | |
"LanguageName": "C", | |
"CodeBlock": "int *v = a;\nwhile (v \u003c a+N)\n{\n int *w = b;\n while (w \u003c b+M)\n {\n if (*v == *w)\n goto OUTER;\n \n ++w;\n }\n printf(\"%d\\n\", *v);\n \n OUTER: ++v;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_N is the length of a.\r\n_M is the length of b.\r\n\r\nUsing _goto is usually considered bad practice in C.", | |
"Version": 1, | |
"VersionDate": "2017-06-05T15:53:59.713578Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3168, | |
"OrigId": 3168, | |
"Author": "sgdpk", | |
"CreationDate": "2019-09-27T03:11:50.496862Z", | |
"LastEditor": "sgdpk", | |
"LanguageName": "Python", | |
"CodeBlock": "for v in a:\n for v_ in b:\n if v == v_:\n continue\n print(v)\n\n# More idiomatic solution for this specific problem\n# \n# for v in a:\n# if v not in b:\n# print(v)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T03:13:07.422569Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3221, | |
"OrigId": 3221, | |
"Author": "Stanley", | |
"CreationDate": "2019-09-27T10:10:40.052639Z", | |
"LastEditor": "Stanley", | |
"LanguageName": "Cpp", | |
"CodeBlock": "auto a = {1,2,3,4,5};\nauto b = {3,5};\n\nfor (auto va: a){\n for (auto vb: b){\n if (va==vb) goto OUTER;\n }\n std::cout \u003c\u003c va \u003c\u003c '\\n';\n OUTER: continue;\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T10:10:40.052639Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3257, | |
"OrigId": 3257, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T13:43:17.746312Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " outer: do i=1,size(a)\n do j=1,size(b)\n if (a(i) == b(j)) cycle outer\n end do\n print *,a(i)\n end do outer", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T13:43:17.746312Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 16, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
43 | |
], | |
"RelatedIdiomTitles": [ | |
"Break outer loop" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 43, | |
"OrigId": 0, | |
"Title": "Break outer loop", | |
"LeadParagraph": "Look for a negative value _v in 2D integer matrix _m. Print it and stop searching. ", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Python] Using enumerate is the pythonic way to iterate while keeping the index", | |
"LastEditedImplID": 2733, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/43/break.png", | |
"Version": 46, | |
"VersionDate": "2019-09-27T03:20:25.898627Z", | |
"Implementations": [ | |
{ | |
"Id": 164, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "mainloop:\n\tfor i, line := range m {\n\t\tfor _, v := range line {\n\t\t\tif v \u003c 0 {\n\t\t\t\tfmt.Println(v)\n\t\t\t\tbreak mainloop\n\t\t\t}\n\t\t}\n\t}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/uthiN89xX4", | |
"DocumentationURL": "https://golang.org/ref/spec#Break_statements", | |
"AuthorComment": "_mainloop is a label used to refer to the outer loop.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 166, | |
"OrigId": 166, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "mainloop: for(int i=0;i\u003cm.length;i++)\n\tfor(int j=0;j\u003cm[i].length;j++)\n\t\tif(m[i][j]\u003c0){\n\t\t\tSystem.out.println(m[i][j]);\n\t\t\tbreak mainloop;\n\t\t}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://ideone.com/GfDlKH", | |
"DocumentationURL": "", | |
"AuthorComment": "_mainloop is a label used to refer to the outer loop.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 262, | |
"OrigId": 262, | |
"Author": "Idiom Master", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "MatthewH", | |
"LanguageName": "Cpp", | |
"CodeBlock": "auto indices = findNegativeValue (m, 10, 20);\nstd::cout \u003c\u003c m[indices.first][indices.second] \u003c\u003c '\\n';\n\nstd::pair\u003cint, int\u003e findNegativeValue (int **m, int rows, int columns) {\n for (int i = 0; i \u003c rows; ++i) {\n for (int j = 0; j \u003c columns; ++j) {\n if (m[i][j] \u003c 0) return make_pair (i, j);\n }\n }\n throw \"No negative value!\";\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Whenever the code is as complicated as you need to break the outer loop, it is the correct time to add a new function.\r\n\r\nedit: The above comment is an opinion and adds nothing to presenting a solution to the stated problem. It is a narrow-minded opinion to think such a statement can apply to every conceivable situation.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:38:12.468002Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "#include \u003ciostream\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 319, | |
"OrigId": 319, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "OUTER:\nfor my $row (@m) {\n for $v (@$row) {\n if ($v \u003c 0) {\n print \"Negative value found: $v\\n\";\n last OUTER;\n }\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 371, | |
"OrigId": 371, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "OUTER:\nfor (var i in m) {\n for (var i in m[i]) {\n if (m[i][j] \u003c 0) {\n console.log(\"Negative value found: \"+m[i][j]);\n break OUTER;\n }\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 398, | |
"OrigId": 398, | |
"Author": "killercup", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "'outer: for v in m {\n 'inner: for i in v {\n if i \u003c 0 {\n println!(\"Found {}\", i);\n break 'outer;\n }\n }\n}", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/22906579/1254484", | |
"DemoURL": "http://is.gd/Uw926A", | |
"DocumentationURL": "", | |
"AuthorComment": "Loop label syntax is similar to lifetimes.", | |
"Version": 2, | |
"VersionDate": "2018-12-17T19:45:20.598669Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 481, | |
"OrigId": 481, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "MatthewH", | |
"LanguageName": "C", | |
"CodeBlock": "int i,j;\nfor(i=0;i\u003csizeof(m)/sizeof(*m);i++)\n{\n\tfor(j=0;j\u003csizeof(*m)/sizeof(**m);j++)\n\t{\n\t\tif(m[i][j]\u003c0)\n\t\t{\n\t\t\tprintf(\"%d\\n\",m[i][j]);\n\t\t\tgoto end;\n\t\t}\n\t}\n}\nend:", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "only works if _m is allocated statically or on the stack, not if allocated in the heap.\r\n\r\nedit: the statement above is misleading. It is referring to the use of _sizeof() to set up the loops, and has nothing to do with using _goto to break the loop. Using _goto to break the loop will work as written, regardless of how the variables are allocated.", | |
"Version": 2, | |
"VersionDate": "2019-09-26T17:31:27.903127Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdio.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 522, | |
"OrigId": 522, | |
"Author": "jwhear", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "jwhear", | |
"LanguageName": "D", | |
"CodeBlock": "outer:\nforeach (i; 0 .. m.length)\n{\n\tforeach (j; 0 .. m[i].length)\n\t{\n\t\tif (m[i][j] \u003c 0)\n\t\t{\n\t\t\twriteln(m[i][j]);\n\t\t\tbreak outer;\n\t\t}\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "D has labeled break and continue statements.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.writeln;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 636, | |
"OrigId": 636, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "OUTER: for (var i = 0; i \u003c m.length; i++) {\n for (var j = 0; j \u003c m[i].length; j++) {\n if (m[i][j] \u003c 0) {\n print(\"Negative value found at $i,$j: ${m[i][j]}\");\n break OUTER;\n }\n }\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/9cdbc88c899c75518d1e", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 676, | |
"OrigId": 676, | |
"Author": "cym13", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "cym13", | |
"LanguageName": "Python", | |
"CodeBlock": "class BreakOuterLoop (Exception): pass\n\ntry:\n position = None\n for row in m:\n for column in m[row]:\n if m[row][column] == v:\n position = (row, column)\n raise BreakOuterLoop\nexcept BreakOuterLoop:\n pass", | |
"OriginalAttributionURL": "http://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops-in-python", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "This is ugly because the pythonic way to solve this problem would be to refactor so that one doesn't have to break out of multiple loops. See PEP3136", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 724, | |
"OrigId": 724, | |
"Author": "jc99", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var i,j: integer;\n flag:boolean;\n[...]\nfor i := 0 to length(m) * length(m[0]) - 1 do\nbegin\n v := m[i mod length(m), i div length(m)];\n if v \u003c 0 then\n begin\n writeln(v);\n break;\n end;\nend;\n\nfor i := 0 to high(m) do\nbegin\n for v in m[i] do\n begin\n flag := (v \u003c 0);\n if flag then\n begin\n writeln(v);\n break;\n end;\n end;\n if flag then\n break;\nend;\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "2 Solutions:\r\n1. do it with one loop.\r\n2. Break both loops with a flag.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 892, | |
"OrigId": 892, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "negative_value = catch :negative do\n matrix.each do |row|\n row.each do |value|\n throw :negative, value if value \u003c 0\n end\n end\nend\n\nputs negative_value", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 951, | |
"OrigId": 951, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "JH", | |
"LanguageName": "Haskell", | |
"CodeBlock": "(print . head . filter (\u003c0) . concat) m\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Haskell's lazy evaluator takes care of breaking all looping when no more searching is needed beyond the first found negative", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1134, | |
"OrigId": 1134, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:59.387368Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "find_negative_in([]) -\u003e undefined;\nfind_negative_in([Row|Rows]) -\u003e find_negative_in(Row, Rows).\n\nfind_negative_in([], Rows) -\u003e find_negative_in(Rows);\nfind_negative_in([Pos|Values], Rows) when Pos \u003e= 0 -\u003e\n\tfind_negative_in(Values, Rows);\nfind_negative_in([Neg|_], _) -\u003e Neg.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=04f3", | |
"DocumentationURL": "", | |
"AuthorComment": "Assuming the matrix is implemented as a list of lists.\r\nWe just use a recursive function that instead of printing the value, just _returns it.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.387368Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1549, | |
"OrigId": 1549, | |
"Author": "nvius", | |
"CreationDate": "2016-02-19T21:39:41.396234Z", | |
"LastEditor": "nvius", | |
"LanguageName": "PHP", | |
"CodeBlock": "for ($y = 0; $y \u003c count($m); $y++) {\r\n for ($x = 0; $x \u003c count($m[$y]); $x++) {\r\n if ($m[$y][$x] == $v) {\r\n break 2;\r\n }\r\n }\r\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/control-structures.break.php", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-19T21:39:41.396234Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1676, | |
"OrigId": 1676, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T09:54:07.417388Z", | |
"LastEditor": "dromer", | |
"LanguageName": "Lua", | |
"CodeBlock": "breakout = false\nfor i,v1 in ipairs(m) do\n for j,v2 in ipairs(v1) do\n if v2 \u003c 0 then\n print(v2)\n state = \"found\"\n breakout = true\n break\n end\n end\n if breakout then break end\nend", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "1) First _break breaks out of the inner-loop. Second _break breaks out of the outer-loop.\r\n2) Simplifying is possible. Change line 11 in _if (_state == \"_found\") _then _break _end and remove lines 1 and 7.\r\n3) No goto-statement.\r\n4) As Nepta wrote: using a function might be another solution, as an example see http://www.programming-idioms.org/idiom/20/return-two-values/1661/lua", | |
"Version": 3, | |
"VersionDate": "2017-10-20T22:53:11.153835Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2733, | |
"OrigId": 2733, | |
"Author": "Rochelimit", | |
"CreationDate": "2019-09-26T14:22:03.939368Z", | |
"LastEditor": "sgdpk", | |
"LanguageName": "Python", | |
"CodeBlock": "def loop_breaking(m, v): \n for i, row in enumerate(m): \n for j, value in enumerate(row): \n if value == v: \n return (i, j)\n return None\n\nprint(loop_breaking(([1,2,3],[4,5,6],[7,8,9]), 6))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Rather than set break flags, it is better to refactor into a function, then use return to break from all nested loops.", | |
"Version": 2, | |
"VersionDate": "2019-09-27T03:20:25.894658Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2813, | |
"OrigId": 2813, | |
"Author": "_darkcha0s", | |
"CreationDate": "2019-09-26T15:33:53.491637Z", | |
"LastEditor": "_darkcha0s", | |
"LanguageName": "Csharp", | |
"CodeBlock": "bool keepLooping = true;\n\nfor(int i = 0; i \u003c m.length \u0026\u0026 keepLooping; i++)\n{\n\tfor(int j = 0; j \u003c m[i].length \u0026\u0026 keepLooping; j++)\n\t{\n\t\tif(m[i][j] \u003c 0)\n\t\t{\n\t\t\tConsole.WriteLine(m[i][j]);\n\t\t\tkeepLooping = false;\n\t\t}\n\t}\n}", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Trying to avoid GOTO with this implementation. ", | |
"Version": 2, | |
"VersionDate": "2019-09-26T15:35:03.019082Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2862, | |
"OrigId": 2862, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:18:12.723914Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(loop named outer\n for i below (array-dimension m 0)\n do (loop for j below (array-dimension m 1)\n for v = (aref m i j)\n when (minusp v)\n do (progn\n (print v)\n (return-from outer))))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:18:12.723914Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2887, | |
"OrigId": 2887, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T16:45:00.550528Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " outer: do j=1, size(m,2)\n do i=1, size(m,1)\n v = m(i,j)\n if (v \u003c 0) then\n print *,v\n exit outer\n end if\n end do\n end do outer", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:45:00.550528Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 20, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
42 | |
], | |
"RelatedIdiomTitles": [ | |
"Continue outer loop" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 44, | |
"OrigId": 0, | |
"Title": "Insert element in list", | |
"LeadParagraph": "Insert element _x at position _i in list _s. Further elements must be shifted to the right.", | |
"ExtraKeywords": "", | |
"Author": "anonymous", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Fortran implementation by user [tkoenig]", | |
"LastEditedImplID": 3258, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/44/insert.png", | |
"Version": 34, | |
"VersionDate": "2019-09-27T13:45:31.280489Z", | |
"Implementations": [ | |
{ | |
"Id": 171, | |
"OrigId": -1, | |
"Author": "anonymous", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "s = append(s, 0)\r\ncopy(s[i+1:], s[i:])\r\ns[i] = x", | |
"OriginalAttributionURL": "https://github.com/golang/go/wiki/SliceTricks", | |
"DemoURL": "http://play.golang.org/p/p2MRxxkyq1", | |
"DocumentationURL": "https://golang.org/pkg/builtin/#append", | |
"AuthorComment": "Extend slice by 1 (it may trigger a copy of the underlying array).\r\nThen shift elements to the right.\r\nThen set _s[_i].", | |
"Version": 2, | |
"VersionDate": "2016-09-27T11:32:58.240943Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 176, | |
"OrigId": 176, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "s.add(i, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://docs.oracle.com/javase/7/docs/api/java/util/List.html#add%28int,%20E%29", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import java.util.List;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 190, | |
"OrigId": 190, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "s.insert(i, x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 320, | |
"OrigId": 320, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Perl", | |
"CodeBlock": "splice(@s, $i, 0, $x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The _0 tells splice we're replacing zero elements with _$x at position _$i, resulting in an insertion rather than replacement. ", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 372, | |
"OrigId": 372, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "JS", | |
"CodeBlock": "s.splice(i, 0, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 451, | |
"OrigId": 451, | |
"Author": "killercup", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "s.insert(i, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://is.gd/70EXU4", | |
"DocumentationURL": "http://doc.rust-lang.org/std/vec/struct.Vec.html#method.insert", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 466, | |
"OrigId": 466, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "array_splice($s, $i, 0, $x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 552, | |
"OrigId": 552, | |
"Author": "JackStouffer", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "D", | |
"CodeBlock": "s.insertInPlace(i, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import std.array;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 637, | |
"OrigId": 637, | |
"Author": "a14n", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "a14n", | |
"LanguageName": "Dart", | |
"CodeBlock": "s.insert(i, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/6190b6c5551043592882", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 688, | |
"OrigId": 688, | |
"Author": "Bart", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "s.Insert(i, x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.freepascal.org/docs-html/rtl/classes/tlist.insert.html", | |
"AuthorComment": "_s is a _TList.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "Uses Classes;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 867, | |
"OrigId": 867, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "s.insert(i, x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/Array.html#method-i-insert", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 926, | |
"OrigId": 926, | |
"Author": "ventsislaf", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "ventsislaf", | |
"LanguageName": "Elixir", | |
"CodeBlock": "List.insert_at(s, i, x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/408363a125", | |
"DocumentationURL": "http://elixir-lang.org/docs/v1.0/elixir/List.html#insert_at/3", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 952, | |
"OrigId": 952, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "take i s ++ x : drop i s\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1262, | |
"OrigId": 1262, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:59.441924Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "{Left, Right} = lists:split(I-1, S),\nLeft ++ [X|Right].\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=0ff3", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.441924Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1679, | |
"OrigId": 1679, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T14:26:44.903404Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "table.insert(s,i,x)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/5w098fMZ", | |
"DocumentationURL": "http://www.lua.org/manual/5.3/manual.html#pdf-table.insert", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-07T14:26:44.903404Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2313, | |
"OrigId": 2313, | |
"Author": "fantasy", | |
"CreationDate": "2018-05-08T01:35:40.189749Z", | |
"LastEditor": "fantasy", | |
"LanguageName": "Cpp", | |
"CodeBlock": "s.insert (s.begin () + i, x);\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2018-05-08T01:35:40.189749Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2858, | |
"OrigId": 2858, | |
"Author": "TotallyGatsby", | |
"CreationDate": "2019-09-26T16:11:54.312974Z", | |
"LastEditor": "TotallyGatsby", | |
"LanguageName": "Csharp", | |
"CodeBlock": "s.Insert(i, x);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.insert?view=netframework-4.8", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:11:54.312974Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System.Collections.Generic;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3258, | |
"OrigId": 3258, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-27T13:45:31.277632Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": "integer, dimension(:), allocatable :: s\n\ns = [s(1:i-1), x, s(i:)]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T13:45:31.277632Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 18, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
158, | |
171 | |
], | |
"RelatedIdiomTitles": [ | |
"Random sublist", | |
"Add an element at the end of a list" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 45, | |
"OrigId": 0, | |
"Title": "Pause execution for 5 seconds", | |
"LeadParagraph": "Sleep for 5 seconds in current thread, before proceeding with next instructions.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Fortran] usleep is a nicer example than sleep", | |
"LastEditedImplID": 3149, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/45/Pause_5s.png", | |
"Version": 49, | |
"VersionDate": "2019-09-27T00:27:09.074998Z", | |
"Implementations": [ | |
{ | |
"Id": 173, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "time.Sleep(5 * time.Second)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/q_MCP3SHWG", | |
"DocumentationURL": "http://golang.org/pkg/time/#Sleep", | |
"AuthorComment": "Unit is _Duration, an alias for _int64 representing a number of nanoseconds.\r\nBut the constant _Second helps readability.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"time\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 174, | |
"OrigId": 174, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "setTimeout(function(){\n\t// Instructions after delay\n},5000);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en/docs/Web/API/WindowTimers/setTimeout", | |
"AuthorComment": "Javascript does not have a _sleep function. The execution flow must be structured with a callback (it can be a closure).\r\nUnit is millisecond.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 175, | |
"OrigId": 175, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "Thread.sleep(5000);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Unit is millisecond", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 321, | |
"OrigId": 321, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "sleep 5;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 436, | |
"OrigId": 436, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "sleep(5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 483, | |
"OrigId": 483, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "usleep(5000000);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_usleep argument is in microseconds.\r\nSee : man 3 usleep ", | |
"Version": 3, | |
"VersionDate": "2017-01-01T22:02:06.025973Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cunistd.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 484, | |
"OrigId": 484, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "LightDiscord", | |
"LanguageName": "Rust", | |
"CodeBlock": "thread::sleep(time::Duration::from_secs(5));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://doc.rust-lang.org/std/thread/fn.sleep.html", | |
"AuthorComment": "", | |
"Version": 4, | |
"VersionDate": "2018-06-16T12:17:22.747936Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "use std::{thread, time};", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 561, | |
"OrigId": 561, | |
"Author": "bbtemp", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "cctemp", | |
"LanguageName": "D", | |
"CodeBlock": "Thread.sleep(5.seconds);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import core.thread;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 570, | |
"OrigId": 570, | |
"Author": "JackStouffer", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "JackStouffer", | |
"LanguageName": "Python", | |
"CodeBlock": "time.sleep(5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import time", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 616, | |
"OrigId": 616, | |
"Author": "a14n", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "kuef", | |
"LanguageName": "Dart", | |
"CodeBlock": "sleep(const Duration(seconds: 5));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://api.flutter.dev/flutter/dart-io/sleep.html", | |
"AuthorComment": "_sleep is only available if _dart:_io is available (ie. on server side)\r\n\r\nAttention! sleep stops all asynchronous execution within the whole Isolate, e.g. will stop all updates for the complete Flutter GUI for that time.", | |
"Version": 2, | |
"VersionDate": "2019-09-13T16:14:02.375438Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import 'dart:io';", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 725, | |
"OrigId": 725, | |
"Author": "jc99", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "jc99", | |
"LanguageName": "Pascal", | |
"CodeBlock": "sleep(5000);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "SysUtils", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 727, | |
"OrigId": 727, | |
"Author": "LRHN", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "await new Future.delayed(const Duration(seconds : 5));", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Waiting makes sense in asynchronous code. It's not done that often, and there is no simple primitive for it.\r\n\r\nThis will not pause the *thread*, but will delay the rest of the current async function.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"dart:async\";", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 766, | |
"OrigId": 766, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "VB", | |
"CodeBlock": "System.Threading.Thread.Sleep(5000)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "System.Threading", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 824, | |
"OrigId": 824, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "Control.Concurrent.threadDelay 5000000\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/package/base/docs/Control-Concurrent.html#v:threadDelay", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 830, | |
"OrigId": 830, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "sleep 5", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-sleep", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 908, | |
"OrigId": 908, | |
"Author": "anonyfox", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "Process.sleep(5000)\r\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/411419bf3c", | |
"DocumentationURL": "https://hexdocs.pm/elixir/Process.html#sleep/1", | |
"AuthorComment": "Sleeps the current process.\r\n\r\nArgument is either the number of milliseconds to sleep as an integer or the atom :_infinity. When :_infinity is given, the current process will suspend forever.", | |
"Version": 4, | |
"VersionDate": "2017-02-07T22:09:11.771529Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1067, | |
"OrigId": 1067, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-11-30T12:37:29.012454Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "timer:sleep(5000).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/timer.html?i=0\u0026search=timer:sle#sleep/1", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.012454Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1318, | |
"OrigId": 1318, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T16:03:35.325048Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "local start = os.clock()\r\nwhile os.clock() - start \u003c 5 do end", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:03:35.325048Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1335, | |
"OrigId": 1335, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-16T16:55:51.120525Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "delay 5.0;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:55:51.120525Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1354, | |
"OrigId": 1354, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-16T17:45:36.126125Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "Thread.Sleep(5000);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://msdn.microsoft.com/en-us/library/system.threading.thread.sleep%28v=vs.110%29.aspx", | |
"AuthorComment": "Takes an _int value representing milliseconds.", | |
"Version": 2, | |
"VersionDate": "2017-03-07T10:31:16.650414Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "using System.Threading;", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1360, | |
"OrigId": 1360, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T17:59:47.707404Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::this_thread::sleep_for(5s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://en.cppreference.com/w/cpp/thread/sleep_for", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:59:47.707404Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cthread\u003e\r\n#include \u003cchrono\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1440, | |
"OrigId": 1440, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:40:15.066666Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "Thread.sleep(5000)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:40:15.066666Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1509, | |
"OrigId": 1509, | |
"Author": "pgon101a", | |
"CreationDate": "2016-02-17T13:44:57.663926Z", | |
"LastEditor": "pgon101a", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(Thread/sleep 5000)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T13:44:57.663926Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2819, | |
"OrigId": 2819, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:37:50.373291Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(sleep 5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:37:50.373291Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3149, | |
"OrigId": 3149, | |
"Author": "jupiter", | |
"CreationDate": "2019-09-27T00:19:18.915804Z", | |
"LastEditor": "jupiter", | |
"LanguageName": "Fortran", | |
"CodeBlock": "module M_time\ncontains\nsubroutine system_sleep(wait)\nuse,intrinsic :: iso_c_binding, only: c_int\ninteger,intent(in) :: wait\ninteger(kind=c_int):: waited\ninterface\n function c_usleep(msecs) bind (C,name=\"usleep\")\n import\n integer(c_int) :: c_usleep\n integer(c_int),intent(in),VALUE :: msecs\n end function c_usleep\nend interface\n if(wait.gt.0)then\n waited=c_usleep(int(wait,kind=c_int))\n endif\nend subroutine system_sleep\nend module M_time\nprogram x\nuse M_time\ncall system_sleep(5000000)\nend ", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Fortran does not have an intrinsic to pause for a specified time period, but it is relatively easy to create an interface to a POSIX C routine\r\n", | |
"Version": 2, | |
"VersionDate": "2019-09-27T00:27:09.070797Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 25, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
185 | |
], | |
"RelatedIdiomTitles": [ | |
"Execute function in 30 seconds" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 46, | |
"OrigId": 0, | |
"Title": "Extract beginning of string (prefix)", | |
"LeadParagraph": "Create string _t consisting of the 5 first characters of string _s.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "nsmryan", | |
"EditSummary": "New Cobol implementation by user [Roie8]", | |
"LastEditedImplID": 3360, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/47/string_prefix_t.png", | |
"Version": 43, | |
"VersionDate": "2019-09-27T23:12:58.379757Z", | |
"Implementations": [ | |
{ | |
"Id": 177, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "String t = s.substring(0,5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_s must not be null.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 179, | |
"OrigId": 179, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var t = s.substring(0,5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring", | |
"AuthorComment": "s._substr(0,5) would also work in that specific case.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 191, | |
"OrigId": 191, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "t = s[:5]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 207, | |
"OrigId": 207, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var t = s.substring(0, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-core.String#id_substring", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 310, | |
"OrigId": 310, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "$t = substr($s, 0, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 421, | |
"OrigId": 421, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "$t = mb_substr($s, 0, 5, 'UTF-8');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 477, | |
"OrigId": 477, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "Datadog", | |
"LanguageName": "C", | |
"CodeBlock": "char *t=(char *)calloc(6,sizeof(char));\nstrncpy(t,s,5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T16:15:08.780701Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e\r\n#include \u003cstring.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 478, | |
"OrigId": 478, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "freecoder", | |
"LanguageName": "Rust", | |
"CodeBlock": "let t = s[..5].to_string();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-12-17T18:31:39.433175Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 563, | |
"OrigId": 563, | |
"Author": "bbtemp", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "bbtemp", | |
"LanguageName": "D", | |
"CodeBlock": "string t = s[0..5];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 689, | |
"OrigId": 689, | |
"Author": "Bart", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Pascal", | |
"CodeBlock": "_t := Copy(_s, 1, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The code is safe even if _s has less than 5 characters.", | |
"Version": 2, | |
"VersionDate": "2016-02-24T15:58:25.333561Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 782, | |
"OrigId": 782, | |
"Author": "nsmryan", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "t :: String\nt = take 5 s", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "The function _take has two arguments: the number of characters to take as a prefix, and the string to take the prefix from. The function _take is in the Haskell prelude and doesn't need to be imported.\r\n\r\nThe type signature is optional, and could be omitted leaving the second line.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 783, | |
"OrigId": 783, | |
"Author": "nsmryan", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "t :: T.Text\nt = T.take 5 s", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://hackage.haskell.org/package/text", | |
"AuthorComment": "This implementation uses the _Text type, imported as suggested in the Text library documentation.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import qualified Data.Text as T", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 841, | |
"OrigId": 841, | |
"Author": "splattael", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "t = s[0, 5]\n# OR\nt = s.slice(0, 5)\nt = s.slice(0...5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-2.2.3/String.html#method-i-slice", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 910, | |
"OrigId": 910, | |
"Author": "zhyu", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "t = String.slice(s, 0, 5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/a6e74b4551", | |
"DocumentationURL": "http://elixir-lang.org/docs/stable/elixir/String.html#slice/3", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T21:30:44.509336Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1111, | |
"OrigId": 1111, | |
"Author": "ufm", | |
"CreationDate": "2015-11-30T12:37:29.084287Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "t := string([]rune(s)[:5])", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/KvXiBYv9Y6", | |
"DocumentationURL": "https://golang.org/ref/spec#Conversions", | |
"AuthorComment": "This \"incurs a run-time cost\" proportional to _len(_s).", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.084287Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1124, | |
"OrigId": 1124, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T02:49:37.043296Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "[A, B, C, D, E | _] = S,\r\nT = [A, B, C, D, E].", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erlang.org/doc/reference_manual/patterns.html", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-12-18T02:49:37.043296Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1125, | |
"OrigId": 1125, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2015-12-18T02:53:31.486936Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "T = string:sub_string(S, 1, 5),\r\nT = string:substr(S, 1, 5).", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=19f3", | |
"DocumentationURL": "http://erldocs.com/current/stdlib/string.html?i=22\u0026search=string:#sub_string/2", | |
"AuthorComment": "The second argument for _substr is the length, for _sub_string it's the last position", | |
"Version": 1, | |
"VersionDate": "2015-12-18T02:53:31.486936Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1320, | |
"OrigId": 1320, | |
"Author": "jparoz", | |
"CreationDate": "2016-02-16T16:06:36.487807Z", | |
"LastEditor": "jparoz", | |
"LanguageName": "Lua", | |
"CodeBlock": "t = s:sub(5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:06:36.487807Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1336, | |
"OrigId": 1336, | |
"Author": "Smaehtin", | |
"CreationDate": "2016-02-16T16:57:16.020331Z", | |
"LastEditor": "Smaehtin", | |
"LanguageName": "Ada", | |
"CodeBlock": "T : String := S (1 .. 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T16:57:16.020331Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1349, | |
"OrigId": 1349, | |
"Author": "zehberk", | |
"CreationDate": "2016-02-16T17:21:02.344359Z", | |
"LastEditor": "zehberk", | |
"LanguageName": "Csharp", | |
"CodeBlock": "string t = s.Substring(0, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_s cannot be null.\r\n\r\nThrows _ArgumentOutOfRangeException if length is less than 5.", | |
"Version": 1, | |
"VersionDate": "2016-02-16T17:21:02.344359Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1363, | |
"OrigId": 1363, | |
"Author": "GhassanPL", | |
"CreationDate": "2016-02-16T18:01:28.836402Z", | |
"LastEditor": "GhassanPL", | |
"LanguageName": "Cpp", | |
"CodeBlock": "auto t = s.substr(0, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://www.cplusplus.com/reference/string/string/substr/", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T18:01:28.836402Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1441, | |
"OrigId": 1441, | |
"Author": "meshelton", | |
"CreationDate": "2016-02-16T21:41:08.015983Z", | |
"LastEditor": "meshelton", | |
"LanguageName": "Scala", | |
"CodeBlock": "val s = \"somestring\"\r\nval t = s.take(5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-16T21:41:08.015983Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1526, | |
"OrigId": 1526, | |
"Author": "pgon101a", | |
"CreationDate": "2016-02-17T22:46:21.494816Z", | |
"LastEditor": "pgon101a", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(take 5 \"abcdefjhi\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T22:46:21.494816Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2856, | |
"OrigId": 2856, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:10:07.839193Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(setf *t* (subseq s 0 5))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:10:07.839193Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3077, | |
"OrigId": 3077, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:23:30.846159Z", | |
"LastEditor": "tkoenig", | |
"LanguageName": "Fortran", | |
"CodeBlock": " character(len=5) :: t\n t = s(1:5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T20:23:30.846159Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3139, | |
"OrigId": 3139, | |
"Author": "miguel", | |
"CreationDate": "2019-09-26T22:37:33.858614Z", | |
"LastEditor": "miguel", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val t = s.take(5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T22:37:33.858614Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3360, | |
"OrigId": 3360, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-27T23:12:58.375076Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. prefix 5.\nPROCEDURE DIVISION.\n MOVE s(1:5) TO t \t\nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:12:58.375076Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 27, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
47, | |
38, | |
96, | |
167 | |
], | |
"RelatedIdiomTitles": [ | |
"Extract string suffix", | |
"Extract a substring", | |
"Check string prefix", | |
"Trim prefix" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 47, | |
"OrigId": 0, | |
"Title": "Extract string suffix", | |
"LeadParagraph": "Create string _t consisting in the 5 last characters of string _s.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Cobol implementation by user [Roie8]", | |
"LastEditedImplID": 3373, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/47/string_suffix_t.png", | |
"Version": 42, | |
"VersionDate": "2019-09-27T23:28:52.696136Z", | |
"Implementations": [ | |
{ | |
"Id": 178, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Java", | |
"CodeBlock": "int n = s.length();\nString t = s.substring(n-5,n);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "_s must not be null.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 180, | |
"OrigId": 180, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "var t = s.slice(-5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 198, | |
"OrigId": 198, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Python", | |
"CodeBlock": "t = s[-5:]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 209, | |
"OrigId": 209, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Dart", | |
"CodeBlock": "var n = s.length;\nvar t = s.substring(n-5, n);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 224, | |
"OrigId": 224, | |
"Author": "Nico", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Ruby", | |
"CodeBlock": "t=s[-5..-1]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://ruby-doc.org/core-1.8.6/String.html#method-i-5B-5D", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 304, | |
"OrigId": 304, | |
"Author": "Roboticus", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "my $last_five = substr(\"now is the time\", -5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "the stubstr function, like many in perl, lets you address strings and arrays from the end by using a negative number.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 420, | |
"OrigId": 420, | |
"Author": "goran", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "$t = mb_substr($s, -5, null, 'UTF-8');", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-26T22:20:14.307757Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 473, | |
"OrigId": 473, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "C", | |
"CodeBlock": "int len=strlen(s);\nchar *t=malloc(6*sizeof(char));\nstrncpy(t,s+len-6,5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstdlib.h\u003e\r\n#include \u003cstring.h\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 474, | |
"OrigId": 474, | |
"Author": "benaryorg", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let t = s[s.len() - 5..].to_string();", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?version=stable\u0026mode=debug\u0026edition=2018\u0026gist=4dac59e6fbf3e1935442ca05d94bcfdc", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 3, | |
"VersionDate": "2018-12-30T12:04:12.522322Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 551, | |
"OrigId": 551, | |
"Author": "bbtemp", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "D", | |
"CodeBlock": "string t = s[$-5..$];", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-02-21T17:40:51.64603Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 686, | |
"OrigId": 686, | |
"Author": "Bart", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "Bart", | |
"LanguageName": "Pascal", | |
"CodeBlock": "Function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString;\nvar j,l:integer;\nbegin\n l:=length(atext);\n j:=ACount;\n if j\u003el then j:=l;\n Result:=Copy(AText,l-j+1,j);\nend;\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Function RightStr() is part of the StrUtils unit that comes with FreePascal.", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 960, | |
"OrigId": 960, | |
"Author": "Rome", | |
"CreationDate": "2015-11-30T12:37:29.158754Z", | |
"LastEditor": "Rome", | |
"LanguageName": "Haskell", | |
"CodeBlock": "t = drop (length s - 5) s\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2015-11-30T12:37:29.158754Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1180, | |
"OrigId": 1180, | |
"Author": "lck", | |
"CreationDate": "2016-01-02T00:43:17.269179Z", | |
"LastEditor": "lck", | |
"LanguageName": "Go", | |
"CodeBlock": "t := string([]rune(s)[len([]rune(s))-5:])", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.golang.org/p/q9zTW5Zh6c", | |
"DocumentationURL": "", | |
"AuthorComment": "Convert to []_rune because some characters are two or more bytes long.", | |
"Version": 1, | |
"VersionDate": "2016-01-02T00:43:17.269179Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1186, | |
"OrigId": 1186, | |
"Author": "gws", | |
"CreationDate": "2016-01-02T04:15:37.684908Z", | |
"LastEditor": "gws", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(let [t (clojure.string/join (take-last 5 s))])", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-01-02T04:20:17.887152Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1259, | |
"OrigId": 1259, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-01-26T02:19:43.306377Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Erlang", | |
"CodeBlock": "[T5, T4, T3, T2, T1 | _] = lists:reverse(S),\r\nT = [T1, T2, T3, T4, T5].", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://erldocs.com/maint/stdlib/lists.html?i=0\u0026search=lists:rever#reverse/1", | |
"AuthorComment": "A rather complex, but fast solution. Assuming _S has, at least, 5 characters.", | |
"Version": 2, | |
"VersionDate": "2016-01-27T11:04:23.503604Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1505, | |
"OrigId": 1505, | |
"Author": "javasucks", | |
"CreationDate": "2016-02-17T11:28:13.547344Z", | |
"LastEditor": "javasucks", | |
"LanguageName": "Csharp", | |
"CodeBlock": "var t = s.Substring(s.Length - 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-17T11:28:13.547344Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1673, | |
"OrigId": 1673, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-07T09:24:36.717238Z", | |
"LastEditor": "Nepta", | |
"LanguageName": "Lua", | |
"CodeBlock": "t = s:sub(-5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/Eeugl2gi", | |
"DocumentationURL": "http://www.lua.org/manual/5.3/manual.html#pdf-string.sub", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-04-07T09:24:36.717238Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1797, | |
"OrigId": 1797, | |
"Author": "barroco", | |
"CreationDate": "2016-08-23T09:15:34.251554Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "t = String.slice(s, -5, 5)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.elixirbyexample.com/s/c3029ccd32", | |
"DocumentationURL": "http://elixir-lang.org/docs/stable/elixir/String.html#slice/3", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-30T21:28:40.652757Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2857, | |
"OrigId": 2857, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T16:11:47.020665Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(setf *t* (subseq s (- (length s) 5)))", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T16:11:47.020665Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3085, | |
"OrigId": 3085, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T20:36:18.604683Z", | |
"LastEditor": "jupiter", | |
"LanguageName": "Fortran", | |
"CodeBlock": "character(len=5) :: t\nt = s(len(s)-4:)", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-27T02:18:11.581564Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3148, | |
"OrigId": 3148, | |
"Author": "vietjtnguyen", | |
"CreationDate": "2019-09-27T00:04:19.524194Z", | |
"LastEditor": "vietjtnguyen", | |
"LanguageName": "Cpp", | |
"CodeBlock": "// std::string s;\nauto suffix = s.substr(s.length() - 5, 5);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://en.cppreference.com/w/cpp/string/basic_string/substr", | |
"AuthorComment": "Assumes s.length()\u003e=5", | |
"Version": 1, | |
"VersionDate": "2019-09-27T00:04:19.524194Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3373, | |
"OrigId": 3373, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-27T23:28:52.691591Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. suffix.\nPROCEDURE DIVISION.\n MOVE FUNCTION LENGTH(s) TO len\n COMPUTE pos = (len - 5) + 1\n MOVE s(pos:) TO t \t \t\nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-27T23:28:52.691591Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 22, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": [ | |
46, | |
38, | |
97, | |
168 | |
], | |
"RelatedIdiomTitles": [ | |
"Extract beginning of string (prefix)", | |
"Extract a substring", | |
"Check string suffix", | |
"Trim suffix" | |
], | |
"Protected": false | |
}, | |
{ | |
"Id": 48, | |
"OrigId": 0, | |
"Title": "Multi-line string literal", | |
"LeadParagraph": "Assign to variable _s a string literal consisting in several lines of text", | |
"ExtraKeywords": "multiline raw", | |
"Author": "deleplace", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "[Cobol] fix", | |
"LastEditedImplID": 3425, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "", | |
"Version": 59, | |
"VersionDate": "2019-09-28T12:20:47.108994Z", | |
"Implementations": [ | |
{ | |
"Id": 210, | |
"OrigId": -1, | |
"Author": "deleplace", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "deleplace", | |
"LanguageName": "Python", | |
"CodeBlock": "s = \"\"\"Huey\nDewey\nLouie\"\"\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 211, | |
"OrigId": 211, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "s := `Huey\r\nDewey\r\nLouie`", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/7933487/871134", | |
"DemoURL": "", | |
"DocumentationURL": "https://golang.org/ref/spec#String_literals", | |
"AuthorComment": "This is a _raw string literal (not \"interpreted\").", | |
"Version": 2, | |
"VersionDate": "2016-04-22T13:10:59.278177Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 328, | |
"OrigId": 328, | |
"Author": "Roboticus", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "Roboticus", | |
"LanguageName": "Perl", | |
"CodeBlock": "$s = \"Perl normally allows\nstrings to contain newlines.\";\n$s = q{\nThere are a good few ways to create multiline\ntext strings in perl.\n};\n$s =\u003c\u003cEOSTR;\nOne of them is called the \"here doc\" (lifted from various UNIX shells).\nA 'here doc' is the \u003c\u003ctag construct. Perl continues to treat\nall the text found as part of the string until there's a line containing\nthe EOSTR tag at the beginning\nEOSTR", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 435, | |
"OrigId": 435, | |
"Author": "benaryorg", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let s = \"line 1\nline 2\nline 3\";", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/29483453/3369597", | |
"DemoURL": "http://is.gd/xvDCI4", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 440, | |
"OrigId": 440, | |
"Author": "goran", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "goran", | |
"LanguageName": "PHP", | |
"CodeBlock": "$s = \"This string \nis spanning\nthree lines\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 503, | |
"OrigId": 503, | |
"Author": "bbtemp", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "bbtemp", | |
"LanguageName": "D", | |
"CodeBlock": "auto str = \"One,\nTwo,\nThree\n\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "line endings and whites are included in the string", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 628, | |
"OrigId": 628, | |
"Author": "meep", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "meep", | |
"LanguageName": "Dart", | |
"CodeBlock": "var s = '''A\nmulti-line\nstring''';", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://dartpad.dartlang.org/bda0ae2261fb6edd937c", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 697, | |
"OrigId": 697, | |
"Author": "Bart", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "Bart", | |
"LanguageName": "Pascal", | |
"CodeBlock": "var \n _s: String;\nbegin\n _s := 'one' + LineEnding + 'two' + LineEnding + 'three'\nend.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "LineEnding is defined as a constant in FreePascal. It's implementation is platform dependant.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 877, | |
"OrigId": 877, | |
"Author": "splattael", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "splattael", | |
"LanguageName": "Ruby", | |
"CodeBlock": "s = \"Spanning\nstring\nworks\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 904, | |
"OrigId": 904, | |
"Author": "knewter", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "s = \"Spanning\r\nstring\r\nworks\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://elixirplayground.com?gist=04bf2e6d36081c357220b7e6fc374119", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2016-11-21T23:17:21.970172Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 964, | |
"OrigId": 964, | |
"Author": "Rome", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Haskell", | |
"CodeBlock": "s = unlines [\n \"several\"\n ,\"lines\"\n ,\"of\"\n ,\"text\"]", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:unlines", | |
"AuthorComment": "_unlines concatenates a list of strings, inserting a newline between each.\r\nIt is inverse to _lines, which splits a string by newlines", | |
"Version": 4, | |
"VersionDate": "2019-03-26T21:19:50.625591Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1056, | |
"OrigId": 1056, | |
"Author": "elbrujohalcon", | |
"CreationDate": "2016-02-18T16:57:59.794373Z", | |
"LastEditor": "elbrujohalcon", | |
"LanguageName": "Erlang", | |
"CodeBlock": "S = \"Strings\nmay span\nacross multiple lines\"\n\"and they can\"\n\"have as many portions\"\n\"as you want\"\n\"all of them quoted\".", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://tryerl.seriyps.ru/#id=22f3", | |
"DocumentationURL": "http://www.erlang.org/doc/reference_manual/data_types.html#id70609", | |
"AuthorComment": "variables are uppercased here", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.794373Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1688, | |
"OrigId": 1688, | |
"Author": "Nepta", | |
"CreationDate": "2016-04-08T13:34:22.321281Z", | |
"LastEditor": "3", | |
"LanguageName": "Lua", | |
"CodeBlock": "s = [[\nHuey\nDewey\nLouie\n]]\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://codepad.org/8NaUhrTF", | |
"DocumentationURL": "https://www.lua.org/pil/2.4.html", | |
"AuthorComment": "Use double square brackets.", | |
"Version": 4, | |
"VersionDate": "2017-10-27T18:30:58.778294Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1778, | |
"OrigId": 1778, | |
"Author": "BBaz", | |
"CreationDate": "2016-08-13T22:05:27.670136Z", | |
"LastEditor": "BBaz", | |
"LanguageName": "D", | |
"CodeBlock": "auto s = ` line1\r\nline2\r\nline3`;\r\n\r\nauto r = r\" line1\r\nline2\r\nline3`;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "when backticks are used (or _r), escapes sequences are ignored.", | |
"Version": 1, | |
"VersionDate": "2016-08-13T22:05:27.670136Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1853, | |
"OrigId": 1853, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-10-21T08:46:10.471633Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Csharp", | |
"CodeBlock": "string s = @\"Huey\r\nDewey\r\nLouie\";", | |
"OriginalAttributionURL": "http://stackoverflow.com/a/1100273/871134", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "It's called a _verbatim _string _literal.", | |
"Version": 1, | |
"VersionDate": "2016-10-21T08:46:10.471633Z", | |
"Rating": 1, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1907, | |
"OrigId": 1907, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-11-21T23:16:13.814776Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Elixir", | |
"CodeBlock": "s = \"\"\"\r\nmultiline\r\nheredoc\r\n\"\"\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://elixirplayground.com?gist=1a8e2ad1d38103d8ece04dce44ff8e04", | |
"DocumentationURL": "http://elixir-lang.org/getting-started/sigils.html", | |
"AuthorComment": "Triple-quotes starts a _heredoc.", | |
"Version": 2, | |
"VersionDate": "2017-02-07T21:48:47.483886Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 1997, | |
"OrigId": 1997, | |
"Author": "Dodopod", | |
"CreationDate": "2017-05-27T19:35:38.692761Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "C", | |
"CodeBlock": "char *s = \"Huey\\n\"\n \"Dewey\\n\"\n \"Louie\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2017-05-27T22:31:18.464186Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2128, | |
"OrigId": 2128, | |
"Author": "glmdgrielson", | |
"CreationDate": "2017-09-30T18:27:55.471476Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "let s = \"This is a very long string which needs \" +\n \"to wrap across multiple lines because \" +\n \"otherwise my code is unreadable.\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Long_literal_strings", | |
"AuthorComment": "By concatenation.", | |
"Version": 3, | |
"VersionDate": "2017-10-01T11:30:44.625709Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2129, | |
"OrigId": 2129, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-10-01T11:26:47.741895Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "let s = \"This is a very long string which needs \\\nto wrap across multiple lines because \\\notherwise my code is unreadable.\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Long_literal_strings", | |
"AuthorComment": "When using backslashes, indentation inside the string literal must be far left.", | |
"Version": 1, | |
"VersionDate": "2017-10-01T11:26:47.741895Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2130, | |
"OrigId": 2130, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2017-10-01T11:28:01.779101Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "JS", | |
"CodeBlock": "let s = `This is a very long string which needs \nto wrap across multiple lines because \notherwise my code is unreadable.`;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Template_literals", | |
"AuthorComment": "ES6 so-called \"template literals\".", | |
"Version": 1, | |
"VersionDate": "2017-10-01T11:28:01.779101Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2322, | |
"OrigId": 2322, | |
"Author": "vinceve", | |
"CreationDate": "2018-05-16T09:50:24.62601Z", | |
"LastEditor": "vinceve", | |
"LanguageName": "PHP", | |
"CodeBlock": "$s = \u003c\u003c\u003cEOD\nHuey\nDewey\nLouie\nEOD;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc", | |
"AuthorComment": "Heredoc syntax", | |
"Version": 1, | |
"VersionDate": "2018-05-16T09:50:24.62601Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2366, | |
"OrigId": 2366, | |
"Author": "gilescope", | |
"CreationDate": "2018-07-02T14:25:27.611594Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Rust", | |
"CodeBlock": "let s = r#\"Huey\nDewey\nLouie\"#;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "https://play.rust-lang.org/?gist=74d85f4ee293eaeede06db45ec9c8ac2\u0026version=stable\u0026mode=debug\u0026edition=2015", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2018-08-03T21:30:21.340309Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2571, | |
"OrigId": 2571, | |
"Author": "1.7.4", | |
"CreationDate": "2019-01-25T11:45:02.001686Z", | |
"LastEditor": "1.7.4", | |
"LanguageName": "Java", | |
"CodeBlock": "String s = \"This is a very long string which needs \" +\n \"to wrap across multiple lines because \" +\n \"otherwise my code is unreadable.\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Credit goes to the JS equivalent—but I'm not sure how to provide a link.", | |
"Version": 1, | |
"VersionDate": "2019-01-25T11:45:02.001686Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2578, | |
"OrigId": 2578, | |
"Author": "Debaran", | |
"CreationDate": "2019-02-01T06:25:15.997013Z", | |
"LastEditor": "Debaran", | |
"LanguageName": "Scala", | |
"CodeBlock": "val s = \"\"\"line 1\nline 2\nline 3\"\"\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-02-01T06:25:15.997013Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2616, | |
"OrigId": 2616, | |
"Author": "Alexander", | |
"CreationDate": "2019-02-16T07:26:20.4089Z", | |
"LastEditor": "Alexander", | |
"LanguageName": "Clojure", | |
"CodeBlock": "(def s \"Murs, ville,\nEt port,\nAsile\nDe mort,\nMer grise\nOù brise\nLa brise,\nTout dort.\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://clojure.org/reference/reader#_literals", | |
"AuthorComment": "Clojure string literals support newlines directly and standard Java string escape sequences", | |
"Version": 1, | |
"VersionDate": "2019-02-16T07:26:20.4089Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2647, | |
"OrigId": 2647, | |
"Author": "name", | |
"CreationDate": "2019-06-24T21:25:10.127624Z", | |
"LastEditor": "name", | |
"LanguageName": "Lua", | |
"CodeBlock": "str = 'Huey '..\n'Dewey '..\n'Louie'", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Multiline string that doesn't respect line breaks.", | |
"Version": 1, | |
"VersionDate": "2019-06-24T21:25:10.127624Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2680, | |
"OrigId": 2680, | |
"Author": "Dango", | |
"CreationDate": "2019-09-06T11:11:50.105156Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Cpp", | |
"CodeBlock": "std::string multiline = R\"( Earth is a planet.\nSo is the Jupiter)\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "Use raw string literals", | |
"Version": 2, | |
"VersionDate": "2019-09-08T14:55:58.525366Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "#include \u003cstring\u003e", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2798, | |
"OrigId": 2798, | |
"Author": "foobar", | |
"CreationDate": "2019-09-26T15:16:50.838714Z", | |
"LastEditor": "foobar", | |
"LanguageName": "Lisp", | |
"CodeBlock": "(setf s \"a\nb\nc\nd\")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T15:16:50.838714Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2932, | |
"OrigId": 2932, | |
"Author": "nsaleem", | |
"CreationDate": "2019-09-26T17:10:26.389404Z", | |
"LastEditor": "nsaleem", | |
"LanguageName": "JS", | |
"CodeBlock": "let s = `This is a very long string which needs\nto wrap across multiple lines because\notherwise my code is unreadable.`;", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Multi-line_strings", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T17:10:26.389404Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 2998, | |
"OrigId": 2998, | |
"Author": "fojji", | |
"CreationDate": "2019-09-26T18:08:11.384647Z", | |
"LastEditor": "fojji", | |
"LanguageName": "Kotlin", | |
"CodeBlock": "val myStr =\n \"\"\"\n This is my\n multi-line string.\n \"\"\"", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2019-09-26T18:08:11.384647Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3028, | |
"OrigId": 3028, | |
"Author": "tkoenig", | |
"CreationDate": "2019-09-26T19:12:26.257035Z", | |
"LastEditor": "pompito", | |
"LanguageName": "Fortran", | |
"CodeBlock": " s = \"Hello \u0026\n \u0026World\"\n", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "In character context, string literals must begin with an ampersand if split in multiple lines.", | |
"Version": 2, | |
"VersionDate": "2019-09-28T05:50:20.958987Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3407, | |
"OrigId": 3407, | |
"Author": "thethanlaw", | |
"CreationDate": "2019-09-28T04:27:11.162986Z", | |
"LastEditor": "thethanlaw", | |
"LanguageName": "Ada", | |
"CodeBlock": "s : String := \"Will this compile? \" \u0026\n \"Oh yes it will\";", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "I'm assuming this is what is meant by \"consisting in several lines of text.\"\r\n\r\nUse _New_Line for line feeds.", | |
"Version": 1, | |
"VersionDate": "2019-09-28T04:27:11.162986Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 3425, | |
"OrigId": 3425, | |
"Author": "Roie8", | |
"CreationDate": "2019-09-28T12:20:16.196854Z", | |
"LastEditor": "Roie8", | |
"LanguageName": "Cobol", | |
"CodeBlock": "IDENTIFICATION DIVISION.\nPROGRAM-ID. multi-line string.\nDATA DIVISION.\nWORKING-STORAGE SECTION.\n01 s PIC X(20).\n01 str PIC X(5) VALUE 'COBOL'.\n01 str1 PIC X(4) VALUE 'RULE'.\n01 str2 PIC X(3) VALUE 'THE'.\n01 str3 PIC X(5) VALUE 'WORLD'.\nPROCEDURE DIVISION. \n STRING str ' ' str1 ' ' str2 ' ' str3 \n DELIMITED BY SIZE INTO s\nSTOP RUN.", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 2, | |
"VersionDate": "2019-09-28T12:20:47.105644Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
} | |
], | |
"ImplCount": 33, | |
"Rating": 0, | |
"WordsTitle": null, | |
"Words": null, | |
"Checked": false, | |
"RelatedIdiomIds": null, | |
"RelatedIdiomTitles": null, | |
"Protected": false | |
}, | |
{ | |
"Id": 49, | |
"OrigId": 0, | |
"Title": "Split a space-separated string", | |
"LeadParagraph": "Build list _chunks consisting in substrings of input string _s, separated by one or more space characters.", | |
"ExtraKeywords": "", | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.856562Z", | |
"LastEditor": "programming-idioms.org", | |
"EditSummary": "New Cpp implementation by user [example12345]", | |
"LastEditedImplID": 3458, | |
"OriginalAttributionURL": "", | |
"Picture": "", | |
"ImageURL": "https://storage.googleapis.com/programming-idioms-pictures/idiom/49/split.png", | |
"Version": 39, | |
"VersionDate": "2019-09-28T17:12:53.0376Z", | |
"Implementations": [ | |
{ | |
"Id": 215, | |
"OrigId": -1, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.856562Z", | |
"LastEditor": "benaryorg", | |
"LanguageName": "Java", | |
"CodeBlock": "String[] chunks = s.split(\"\\\\s+\");", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "", | |
"AuthorComment": "", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.856562Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 216, | |
"OrigId": 216, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.856562Z", | |
"LastEditor": "programming-idioms.org", | |
"LanguageName": "Go", | |
"CodeBlock": "chunks := strings.Split(s, \" \")", | |
"OriginalAttributionURL": "", | |
"DemoURL": "http://play.golang.org/p/Ns0aC1E2v4", | |
"DocumentationURL": "https://golang.org/pkg/strings/#Split", | |
"AuthorComment": "_chunks has type []string.\r\nWarning: you may get empty strings as items in _chunks because of leading spaces, trailing spaces, and repeated spaces.", | |
"Version": 1, | |
"VersionDate": "2016-02-18T16:57:59.856562Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "import \"strings\"", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 242, | |
"OrigId": 242, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.856562Z", | |
"LastEditor": "???", | |
"LanguageName": "Python", | |
"CodeBlock": "chunks = s.split()", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationURL": "https://docs.python.org/2/library/stdtypes.html", | |
"AuthorComment": "If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive ASCII whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the sequence has leading or trailing whitespace. Consequently, splitting an empty sequence or a sequence consisting solely of ASCII whitespace without a specified separator returns [].", | |
"Version": 2, | |
"VersionDate": "2016-05-29T09:25:03.631065Z", | |
"Rating": 0, | |
"Checked": false, | |
"ImportsBlock": "", | |
"PictureURL": "", | |
"Protected": false | |
}, | |
{ | |
"Id": 244, | |
"OrigId": 244, | |
"Author": "programming-idioms.org", | |
"CreationDate": "2016-02-18T16:57:59.856562Z", | |
"LastEditor": "ancarda", | |
"LanguageName": "PHP", | |
"CodeBlock": "$chunks = preg_split('/ +/', $s);", | |
"OriginalAttributionURL": "", | |
"DemoURL": "", | |
"DocumentationUR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment