1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「Koka」に今来た私が試したこと(ChatGPT先生と共に)

Posted at

はじめに

この記事は、Koka Advent Calendar 2024 の5日目の記事となります。

アドベントカレンダのリストを見ていて、今、Kokaに初めて来た者の記録です。

基本事項

Kokaってなに? というわけでChatGPT先生に聞いてみる。

スクリーンショット 2024-12-17 14.14.14.png

スクリーンショット 2024-12-17 14.14.27.png

スクリーンショット 2024-12-17 14.14.38.png

koka.kk
fun add(x : int, y : int) : int {
  x + y
}

fun main() {
  println("The sum is: \(add(3, 4))")
}

スクリーンショット 2024-12-17 14.22.18.png

なるほど・・分からん・・。
プログラムの例を作ってもらおう。

スクリーンショット 2024-12-17 14.22.51.png

スクリーンショット 2024-12-17 14.23.55.png

koka2.kk
// 安全な割り算関数
fun safe_divide(x : int, y : int) : exn int {
  if (y == 0) {
    throw("Error: Cannot divide by zero") // エラーを発生させる
  } else {
    x / y
  }
}

// main関数
fun main() : console () {
  try {
    // 割り算を試みる
    val result = safe_divide(10, 0)
    println("The result is: \(result)")
  } catch (exn) {
    // エラー処理
    println("An exception occurred: \(exn)")
  }
}

スクリーンショット 2024-12-17 14.25.28.png

スクリーンショット 2024-12-17 14.26.02.png

スクリーンショット 2024-12-17 14.26.25.png

サンプルを実行してみよう

インストール方法

VSCodeの拡張機能で入る!
Cmd+Shift+pで
スクリーンショット 2024-12-17 14.30.53.png

スクリーンショット 2024-12-17 14.33.24.png

all.kkを選んでみる

スクリーンショット 2024-12-17 14.35.20.png

スクリーンショット 2024-12-17 14.37.57.png

実行できた!
とても手軽に始められることがわかりました。

今回はここまで。

最後までご覧いただきましてありがとうございました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?