Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add Julia sample code #3041

Merged
merged 2 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 1 addition & 19 deletions dictionaries/julia/cspell-ext.json
@@ -1,43 +1,25 @@
// cSpell Settings
{
"id": "julia",
"version": "0.2",
"name": "Julia Dictionary",
"description": "Julia function and keyword dictionary",
"readonly": true,
// List of dictionary files to add to the global list of dictionaries
"dictionaryDefinitions": [
{
"name": "julia",
"path": "./dict/julia.txt",
"description": "Julia Dictionary"
}
],
// Dictionaries to always be used.
// Generally left empty
"dictionaries": [],
// Language Rules to apply to matching files.
// Files are matched on `languageId` and `locale`
"enableFiletypes": ["julia"],
"languageSettings": [
{
// VSCode languageId. i.e. typescript, java, go, cpp, javascript, markdown, latex
// * will match against any file type.
"languageId": "julia",
// Language locale. i.e. en-US, de-AT, or ru. * will match all locales.
// Multiple locales can be specified like: "en, en-US" to match both English and English US.
"locale": "*",
// By default the whole text of a file is included for spell checking
// Adding patterns to the "includeRegExpList" to only include matching patterns
"includeRegExpList": [],
// To exclude patterns, add them to "ignoreRegExpList"
"ignoreRegExpList": [],
// regex patterns than can be used with ignoreRegExpList or includeRegExpList
// Example: "pattern": [{ "name": "mdash", "pattern": "—" }]
// This could be included in "ignoreRegExpList": ["mdash"]
"patterns": [],
// List of dictionaries to enable by name in `dictionaryDefinitions`
"dictionaries": ["julia"],
// Dictionary definitions can also be supplied here. They are only used iff "languageId" and "locale" match.
"dictionaryDefinitions": []
}
]
Expand Down
2 changes: 1 addition & 1 deletion dictionaries/julia/cspell.json
@@ -1,7 +1,7 @@
{
"version": "0.2",
"files": [
"**/*.{md,txt}"
"**/*.{md,txt,jl}"
],
"dictionaries": [
"julia"
Expand Down
4 changes: 3 additions & 1 deletion dictionaries/julia/package.json
Expand Up @@ -13,7 +13,9 @@
},
"scripts": {
"build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 cspell-tools-cli build",
"test": "head -n 1000 \"src/julia.txt\" | cspell -v -c ./cspell-ext.json \"--locale=*\" \"--languageId=julia\" stdin",
"test": "pnpm run test:words && pnpm run test:samples",
"test:samples": "cspell samples",
"test:words": "head -n 1000 \"src/julia.txt\" | cspell -c ./cspell-ext.json \"--locale=*\" \"--languageId=julia\" stdin",
"prepublishOnly": "echo OK",
"prepare:dictionary": "pnpm run build"
},
Expand Down
35 changes: 35 additions & 0 deletions dictionaries/julia/samples/code.jl
@@ -0,0 +1,35 @@
# From https://juliabyexample.helpmanual.io/#Simple-Functions

# function to calculate the volume of a sphere
function sphere_vol(r)
# julia allows Unicode names (in UTF-8 encoding)
# so either "pi" or the symbol π can be used
return 4/3*pi*r^3
end

# functions can also be defined more succinctly
quadratic(a, sqr_term, b) = (-b + sqr_term) / 2a

# calculates x for 0 = a*x^2+b*x+c, arguments types can be defined in function definitions
function quadratic2(a::Float64, b::Float64, c::Float64)
# unlike other languages 2a is equivalent to 2*a
# a^2 is used instead of a**2 or pow(a,2)
sqr_term = sqrt(b^2-4a*c)
r1 = quadratic(a, sqr_term, b)
r2 = quadratic(a, -sqr_term, b)
# multiple values can be returned from a function using tuples
# if the return keyword is omitted, the last term is returned
r1, r2
end

vol = sphere_vol(3)
# @printf allows number formatting but does not automatically append the \n to statements, see below
using Printf
@printf "volume = %0.3f\n" vol
#> volume = 113.097

quad1, quad2 = quadratic2(2.0, -2.0, -12.0)
println("result 1: ", quad1)
#> result 1: 3.0
println("result 2: ", quad2)
#> result 2: -2.0