Skip to content

Instantly share code, notes, and snippets.

@antimon2
Last active August 2, 2018 01:23
Show Gist options
  • Save antimon2/1dca9305e9aee13a4df642076e95c4c3 to your computer and use it in GitHub Desktop.
Save antimon2/1dca9305e9aee13a4df642076e95c4c3 to your computer and use it in GitHub Desktop.
Strange Behavior for try-while-errorcondition in Julia v0.7
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-02T10:19:04.255000+09:00",
"start_time": "2018-08-02T01:19:01.333Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Julia Version 0.7.0-rc1.0\n",
"Commit 15fcc7c4e6 (2018-07-31 20:29 UTC)\n",
"Platform Info:\n",
" OS: macOS (x86_64-apple-darwin14.5.0)\n",
" CPU: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz\n",
" WORD_SIZE: 64\n",
" LIBM: libopenlibm\n",
" LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)\n"
]
}
],
"source": [
"versioninfo()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-02T10:19:08.333000+09:00",
"start_time": "2018-08-02T01:19:07.823Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"calc (generic function with 1 method)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function calc(x, y, z)\n",
" if z > 5\n",
" throw(ArgumentError(\"z ($z) must to be ≤ 5.\"))\n",
" end\n",
" x + y * z\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-02T10:19:09.354000+09:00",
"start_time": "2018-08-02T01:19:09.247Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"calc_z (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function calc_z(n)\n",
" z = 0\n",
" try\n",
" while calc(0, 3, z) < n\n",
" z += 1\n",
" end\n",
" catch ex\n",
" if ex isa ArgumentError\n",
" # pass\n",
" else\n",
" rethrow()\n",
" end\n",
" end \n",
" z - 1\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-02T10:19:10.584000+09:00",
"start_time": "2018-08-02T01:19:10.323Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"calc_z(10)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-02T10:19:11.257000+09:00",
"start_time": "2018-08-02T01:19:11.255Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"calc_z(20)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.7.0-rc1",
"language": "julia",
"name": "julia-0.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment