Differences

This shows you the differences between two versions of the page.

Link to this comparison view

code_type [2026/07/31 10:55]
hermann created
code_type [2026/08/18 02:16] (current)
hermann
Line 11: Line 11:
 ===== EGO Script ===== ===== EGO Script =====
  
-Code Type has no literal syntax of its own. A Code value is stored as base64 in the underlying scriptwhich makes it impractical to write directly ​— instead, ​Code constant is always represented as a base64-encoded ​[[String Type|String]] ​literal, converted to Code automatically by the ''​String → Code'' ​conversion. This is why a Code value in a script always appears ​as this conversion rather than as a direct literal. Base64 lets the encoded source keep any charactersquotingor exact whitespace ​and line breaks without needing to escape anything for the script'​s own text syntax:+Code Type has its own literal syntaxparsed ​directly ​rather than going through ​conversion — it accepts either of two forms. 
 + 
 +**Raw string.** The same ''​$"<​delimiter>​( raw_characters )<​delimiter>"''​ syntax used by [[String Type]] constants (see [[string_type#​raw_string_format_starting_on_dinamica_501|String ​Type's Raw String Format]]): ''​raw_characters''​ is used directly ​as the script textwith no encoding involved, and ''<​delimiter>''​ is any character that, together with the closing parenthesis,​ doesn'​t appear inside ​the script ​— it can be omitted entirely when the closing parenthesis alone doesn't appear in the content. This is the form the GUI code editor generates when it writes a constant:
  
 <​code>​ <​code>​
-"aW1wb3J0IG51bXB5IGFzIG5wCmRpbmFtaWNhLm91dHB1dHNbJ3Jlc3VsdCddID0gbnAubWVhbihbMSwgMiwgM10p"+$"(import numpy as np 
 +dinamica.outputs['​result'​] = np.mean([1, 2, 3]))"
 </​code>​ </​code>​
  
-Decodedthis represents:+**Base64.** The legacy double-quoted string syntax (see [[string_type#​legacy|String Type's Legacy]] format)holding the script text encoded as base64:
  
 <​code>​ <​code>​
-import numpy as np +"​aW1wb3J0IG51bXB5IGFzIG5wCmRpbmFtaWNhLm91dHB1dHNbJ3Jlc3VsdCddID0gbnAubWVhbihbMSwgMiwgM10p"​
-dinamica.outputs['​result'​] = np.mean([1, 2, 3])+
 </​code>​ </​code>​
  
-Because of this, Code constants are normally produced by the GUI rather than typed by hand — writing or editing the base64 text manually ​risks introducing invalid base64, which the conversion below rejects.+Decoded, this represents the same script as the raw string example above. Encoding the source ​this way lets it keep any charactersquoting, or exact whitespace and line breaks without needing to escape anything for the script'​s own text syntax — useful for scripts generated or transformed programmatically ​rather than typed directly. Editing ​base64 text by hand risks introducing invalid base64, which the parser ​rejects.
  
 ===== Automatic Conversions ===== ===== Automatic Conversions =====
  
-  * **Converted from**: [[String Type]] — can fail; the string ​must be valid base64. This is most likely to happen if the text was written or edited by hand rather than generated by the GUI.+  * **Converted from**: [[String Type]] — the string's text is taken directly as the script; no base64 encoding is required.
  
-  * **Converted to**: [[String Type]] — the Code value is base64-encoded.+  * **Converted to**: [[String Type]] — produces ​the script'​s textual representation,​ not a base64 ​encoding.
  
 See [[type_system|Type System]] for the complete conversion reference across all types. See [[type_system|Type System]] for the complete conversion reference across all types.
 +