-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"1vUd3SSoOm2K6UQLnkJQursZZx4CaIT_1","timestamp":1714945497637}]},"kernelspec":{"name":"gonb","display_name":"Go (gonb)"}},"cells":[{"cell_type":"markdown","source":["# Unicode Character Literals"],"metadata":{"id":"FWzjioUI63tT"}},{"cell_type":"markdown","source":["Run this notebook in Google Colab."],"metadata":{"id":"i-bezriyHDdD"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"3PaXSu67xkrg","executionInfo":{"status":"ok","timestamp":1714945867744,"user_tz":240,"elapsed":102512,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"7d5ee853-d919-442a-c2f1-742e82717f3d","colab":{"base_uri":"https://localhost:8080/"}},"outputs":[{"output_type":"stream","name":"stdout","text":["Installing go ...env: GOROOT=/content/go\n"," done.\n","go version go1.22.2 linux/amd64\n","Installing gonb ... done.\n","Installing goimports ... done.\n","Installing gopls ... done.\n","I0505 21:51:07.403588 4366 install.go:121] \u001b[7;39;32m[b72d3c03]\u001b[0m Go (gonb) kernel configuration installed in \"/root/.local/share/jupyter/kernels/gonb/kernel.json\".\n","Done!\n"]}],"source":["#@title Install Go, `goimports` and GoNB code in Google Colab\n","\n","# Install Go and goimports.\n","!echo -n \"Installing go ...\"\n","!mkdir -p cache\n","!wget -q -O cache/go.tar.gz 'https://go.dev/dl/go1.22.2.linux-amd64.tar.gz'\n","!tar xzf cache/go.tar.gz\n","%env GOROOT=/content/go\n","!ln -sf \"/content/go/bin/go\" /usr/bin/go\n","!echo \" done.\"\n","!go version\n","\n","# Install gonb, goimports, gopls.\n","!echo -n \"Installing gonb ...\"\n","!go install github.com/janpfeifer/gonb@latest >& /tmp/output || cat /tmp/output\n","!echo \" done.\"\n","!ln -sf /root/go/bin/gonb /usr/bin/gonb\n","\n","!echo -n \"Installing goimports ...\"\n","!go install golang.org/x/tools/cmd/goimports@latest >& /tmp/output || cat /tmp/output\n","!echo \" done.\"\n","!ln -sf /root/go/bin/goimports /usr/bin/goimports\n","\n","!echo -n \"Installing gopls ...\"\n","!go install golang.org/x/tools/gopls@latest >& /tmp/output || cat /tmp/output\n","!echo \" done.\"\n","!ln -sf /root/go/bin/gopls /usr/bin/gopls\n","\n","# Install gonb kernel configuration.\n","!gonb --install --logtostderr\n","!echo \"Done!\""]},{"cell_type":"markdown","source":["The cell above should be run only once, and then followed by a change of runtime to `Go (gonb)`. See detailed instructions above."],"metadata":{"id":"lbPHZ_rjOavo"}},{"cell_type":"markdown","source":["## Valid Character Literals"],"metadata":{"id":"HadGU80XudVz"}},{"cell_type":"code","source":["%%\n","ch1 := 'a'\n","ch2 := '東' // (Not an ASCII character!)\n","ch3 := '𐐀' // (Not a BMP character!)\n","// ch4 := '\\' // (Backslash is a syntax error in Go!)\n","\n","fmt.Printf(\"%c %c %c\\n\", ch1, ch2, ch3)"],"metadata":{"id":"FqH3tlqjsDpV","executionInfo":{"status":"ok","timestamp":1714946946017,"user_tz":240,"elapsed":481,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"41d6db36-9726-49db-f332-b8917290a625","colab":{"base_uri":"https://localhost:8080/"}},"execution_count":1,"outputs":[{"output_type":"stream","name":"stdout","text":["a 東 𐐀\n"]}]},{"cell_type":"markdown","source":["## Unicode Notation in Strings\n","\n","- `\\uHHHH` - where H is a case-insensitive hexadecimal character\n","- Only supports the Basic Multilingual Plane"],"metadata":{"id":"FXz5BuqczgzZ"}},{"cell_type":"code","source":["%%\n","ch5 := '\\u00EA' // ‘ê’\n","str1 := \"a\\u00ea\\u00f1\\u00fcc\" // “aêñüc”\n","str2 := \"A\\u00EA\\u00F1\\u00FCC\" // “AêñüC”\n","\n","fmt.Printf(\"%c\\n\", ch5)\n","fmt.Println(str1)\n","fmt.Println(str2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"aK16puWgzhsl","executionInfo":{"status":"ok","timestamp":1714947118452,"user_tz":240,"elapsed":616,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"7a560cec-d4b4-4977-f026-05c2e3657f3b"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["ê\n","aêñüc\n","AêñüC\n"]}]},{"cell_type":"markdown","source":["## Unicode Code Point Literals\n","\n","- `\\U00HHHHHH` for specifying code point plane and code point for characters outside the BMP"],"metadata":{"id":"prsKwd-m2nT_"}},{"cell_type":"code","source":["%%\n","str3 := \"\\U00010400\" // '𐐀'\n","\n","fmt.Println(str3)\n","fmt.Printf(\"length: %d\\n\", utf8.RuneCountInString(str3))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"lVkkNx5S2oqi","executionInfo":{"status":"ok","timestamp":1714947868441,"user_tz":240,"elapsed":315,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"febbed40-6623-4bfe-e6c4-4e9eba18ff6a"},"execution_count":10,"outputs":[{"output_type":"stream","name":"stdout","text":["𐐀\n","length: 1\n"]}]},{"cell_type":"markdown","source":["## Unicode Code Point Literals as Integers\n","\n","- `0xHHHHHH` for specifying code point plane and code point for characters outside the BMP\n","- Use the `chr()` function"],"metadata":{"id":"CtIvqiZy3C50"}},{"cell_type":"code","source":["%%\n","cp1 := '\\U00010400' // '𐐀'\n","str4 := string(cp1)\n","\n","fmt.Println(str4)\n","fmt.Printf(\"length: %d\\n\", utf8.RuneCountInString(str4))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"mx9GXV4J3EtZ","executionInfo":{"status":"ok","timestamp":1714951765615,"user_tz":240,"elapsed":136,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"8e98b5e4-e949-494e-f656-1a58ff1ae0b3"},"execution_count":13,"outputs":[{"output_type":"stream","name":"stdout","text":["𐐀\n","length: 1\n"]}]},{"cell_type":"markdown","source":["## Escape Sequences"],"metadata":{"id":"6nVgUBOTGmcY"}},{"cell_type":"code","source":["func printUnicode(ch rune) {\n"," fmt.Printf(\"\\\\u%04x\\n\", ch)\n","}\n","\n","%%\n","printUnicode('\\t')\n","printUnicode('\\b')\n","printUnicode('\\n')\n","printUnicode('\\r')\n","printUnicode('\\f')\n","printUnicode('\\'')\n","printUnicode('\"')\n","printUnicode('\\\\')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"KMGAl1njGoJE","executionInfo":{"status":"ok","timestamp":1714952032909,"user_tz":240,"elapsed":657,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"47be2164-bf77-4977-b215-8df2d084876b"},"execution_count":15,"outputs":[{"output_type":"stream","name":"stdout","text":["\\u0009\n","\\u0008\n","\\u000a\n","\\u000d\n","\\u000c\n","\\u0027\n","\\u0022\n","\\u005c\n"]}]}]} |
This file contains 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
This file contains 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
This file contains 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